如今很多應(yīng)用已經(jīng)不再局限于點(diǎn)擊按鈕觸發(fā)事件來(lái)進(jìn)行視圖之間切換,為迎合給予用戶更好體驗(yàn),體現(xiàn)iOS系統(tǒng)極佳用戶體驗(yàn),使用手勢(shì)來(lái)進(jìn)行各個(gè)視圖之間切換,用戶至于一個(gè)大拇指在屏幕中央就可瀏覽到很多信息;
創(chuàng)新互聯(lián)是少有的網(wǎng)站建設(shè)、成都網(wǎng)站制作、營(yíng)銷型企業(yè)網(wǎng)站、小程序設(shè)計(jì)、手機(jī)APP,開發(fā)、制作、設(shè)計(jì)、賣鏈接、推廣優(yōu)化一站式服務(wù)網(wǎng)絡(luò)公司,于2013年創(chuàng)立,堅(jiān)持透明化,價(jià)格低,無(wú)套路經(jīng)營(yíng)理念。讓網(wǎng)頁(yè)驚喜每一位訪客多年來(lái)深受用戶好評(píng)關(guān)于 RNSwipeViewController: https://github.com/rnystrom/RNSwipeViewController
RNSwipeViewController是別人已經(jīng)寫好的一個(gè)ViewController容器,剩下我們要做的就是把自己的視圖容器放到這個(gè)容器中進(jìn)行管理。
首先學(xué)習(xí) RNSwipeViewController里面的Demo
1.創(chuàng)建一個(gè)Single View Application工程,next,勾選 Use Storyboards,Use Automatic Reference Counting
2.將RNSwipeViewController拖入新建到工程,添加QuartzCore.framework
3.新建四個(gè)類CenterViewController、LeftViewController、RightViewController、BottomViewController,繼承UIViewController類
4.打開StoryBoard,從庫(kù)里拖入四個(gè)ViewController視圖控制器到StoryBoard里面,選中一個(gè)視圖控制器設(shè)置類名和Storyboard ID,其他三個(gè)類似
,
5.在ViewController.h將加入#import "RNSwipeViewController.h"并將繼承類改為RNSwipeViewController,在ViewDidLoad方法中
- (void)viewDidLoad { [super viewDidLoad]; CenterViewController *centerView = [self.storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"]; UINavigationController *centerNav = [[UINavigationController alloc] initWithRootViewController:centerView]; centerView.title =@"Center"; self.centerViewController = centerNav; self.leftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"]; self.rightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"]; self.bottomViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"BottomViewController"]; }
如此我們就完成三個(gè)視圖之間手勢(shì)交互,首先出現(xiàn)的視圖作為主視圖,其他試圖再是在它上面進(jìn)行運(yùn)動(dòng),手指向左滑右側(cè)視圖出現(xiàn),向右滑動(dòng)出現(xiàn)左視圖,向上滑動(dòng)出現(xiàn)底部視圖出現(xiàn)
..
平常我們?cè)跇?gòu)建一個(gè)帶有XIB視圖控制類的時(shí)候,初始化一般這樣
CenterViewController *centerVC = [[CenterViewController alloc] initWithNibName:@"CenterViewController" bundle:nil];
但是在StoryBoard中,視圖的Storyboard ID 成了這是視圖的唯一標(biāo)示,再給一個(gè)視圖所屬類時(shí),設(shè)定好該視圖的Storyboard ID,進(jìn)行初始化時(shí)CenterViewController *centerView = [self.storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"];
這個(gè)類庫(kù)中也提供按鈕點(diǎn)擊進(jìn)行視圖交互方法,同時(shí)也設(shè)置視圖顯示寬度的屬性,在類庫(kù)實(shí)現(xiàn)的里面視圖寬度有默認(rèn)值
_leftVisibleWidth = 200.f;
_rightVisibleWidth = 200.f;
_bottomVisibleHeight = 300.0f;
再此我們可以在自己類里修改這個(gè)屬性,根據(jù)自己需求,作圖下設(shè)置
ViewController.m
- (void)viewDidLoad { [super viewDidLoad]; CenterViewController *centerView = [self.storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"]; UINavigationController *centerNav = [[UINavigationController alloc] initWithRootViewController:centerView]; centerView.title =@"Center"; self.centerViewController = centerNav; self.leftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"]; self.leftVisibleWidth = 100; self.rightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"]; self.rightVisibleWidth = self.view.frame.size.width; self.bottomViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"BottomViewController"]; }
我們?cè)俳o導(dǎo)航欄上添加兩個(gè)按鈕,在CenterViewController類中,包含#import "UIViewController+RNSwipeViewController.h"
- (void)viewDidLoad { [super viewDidLoad]; UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom]; leftBtn.frame = CGRectMake(0, 0, 44, 44); [leftBtn setImage:[UIImage p_w_picpathNamed:@"left.png"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(toggleLeft) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftBar = [[UIBarButtonItem alloc] initWithCustomView:leftBtn]; self.navigationItem.leftBarButtonItem = leftBar ; UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; rightBtn.frame = CGRectMake(self.view.frame.size.width-44, 0,44 , 44); [rightBtn setImage:[UIImage p_w_picpathNamed:@"right.png"] forState:UIControlStateNormal]; [rightBtn addTarget:self action:@selector(toggleRight) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightBtn]; self.navigationItem.rightBarButtonItem = rightBar; ; }
接著連個(gè)按鈕事件,為了顯示明顯我們可以設(shè)置一下三個(gè)視圖背景顏色
-(void)toggleLeft { [self.swipeController showLeft]; } -(void)toggleRight { [self.swipeController showRight]; }
RNSwipeViewController有一個(gè)協(xié)議方法,可以監(jiān)聽(tīng)當(dāng)前視圖顯示百分比(0~100)
RNSwipeViewController have a protocol method, can monitor the current view shows percentage (0 ~ 100)
#import <UIKit/UIKit.h> #import "RNRevealViewControllerProtocol.h" @interface LeftViewController : UIViewController<RNRevealViewControllerProtocol> @end
協(xié)議方法,當(dāng)左側(cè)視圖完全顯示時(shí)彈出一個(gè)alertView
-(void)changedPercentReveal:(NSInteger)percent { if (percent == 100) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"這是一個(gè)測(cè)試" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show ]; } }
×××地址:https://github.com/XFZLDXF/XFSwipeView.git
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)頁(yè)名稱:使用RNSwipeViewController類庫(kù)進(jìn)行視圖切換-創(chuàng)新互聯(lián)
URL分享:http://muchs.cn/article10/idpdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、云服務(wù)器、搜索引擎優(yōu)化、手機(jī)網(wǎng)站建設(shè)、定制網(wǎng)站、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容