這篇文章給大家分享的是有關(guān)iOS中如何仿QQ實(shí)現(xiàn)側(cè)滑菜單功能的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
樺南ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!UITabBarController做QQ側(cè)滑菜單效果:
首先要了解UITabBarController的層級(jí)結(jié)構(gòu):
UITabBarController加載的其它UIViewController的View都是被添加在UITransitionView上(這是一個(gè)私有API),UITransitionView在self.view的0層,UITabBar在的第一層。
所以我的思路是這樣的:
UITransitionView與UITabBar轉(zhuǎn)移到一個(gè)新的View1上去,作為滑動(dòng)的部分;
在View1與self.view之間再添加一個(gè)View2,作為菜單的容器;
給View1添加相應(yīng)的手勢(shì)響應(yīng);
代碼:
#import <UIKit/UIKit.h> @protocol SlideTab_VC_TCVDelegate <NSObject> @optional -(void)didOpenMenu:(UIView*)menu; -(void)didCloseMenu:(UIView*)menu; @end @interface SlideTab_VC : UITabBarController @property(strong, nonatomic)UIView *mMenuV; @property(weak, nonatomic)id <SlideTab_VC_TCVDelegate> mDelegate; -(void)openMenu; -(void)closeMenu; @end #import "SlideTab_VC.h" #define DEVICE_W [UIScreen mainScreen].bounds.size.width @interface SlideTab_VC ()<UITabBarDelegate>{ CGFloat _centerMaxX; } @property(strong, nonatomic)UIView *mTransitionView; @property(strong, nonatomic)UITapGestureRecognizer *mTapGester; @property(assign, nonatomic)BOOL mMenuIsOpen; @property(strong, nonatomic)UITabBar *mTabBar; @end @implementation SlideTab_VC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor purpleColor]; _mMenuIsOpen = NO; _centerMaxX = DEVICE_W*3/2-80.0f; [self initMTransitionView]; [self addGestureForMTransitionView]; } #pragma mark 菜單懶加載 -(void)setMMenuV:(UIView *)mMenuV{ if (mMenuV!=nil) { _mMenuV = mMenuV; [self.view insertSubview:_mMenuV atIndex:0]; } } #pragma mark 打開菜單 -(void)openMenu{ CGPoint center = self.mTransitionView.center; center.x = _centerMaxX; [UIView animateWithDuration:0.15f animations:^{ self.mTransitionView.center = center; if (_mDelegate != nil&& [_mDelegate respondsToSelector:@selector(didOpenMenu:)]) { [_mDelegate didOpenMenu:_mMenuV]; } }]; [self mTransitionSubViewsEnable:NO]; } #pragma mark 關(guān)閉菜單 -(void)closeMenu{ CGPoint center = self.mTransitionView.center; center.x = DEVICE_W/2; [UIView animateWithDuration:0.15f animations:^{ self.mTransitionView.center = center; } completion:^(BOOL finished) { [self mTransitionSubViewsEnable:YES]; if (_mDelegate != nil&& [_mDelegate respondsToSelector:@selector(didCloseMenu:)]) { [_mDelegate didCloseMenu:_mMenuV]; } }]; } #pragma mark Transition用戶交互使能 -(void)mTransitionSubViewsEnable:(BOOL)enable{ for (UIView *tmp in self.mTransitionView.subviews) { tmp.userInteractionEnabled = enable; } if (enable) { [self.mTransitionView removeGestureRecognizer:_mTapGester]; }else{ [self.mTransitionView addGestureRecognizer:_mTapGester]; } } #pragma mark 配置mTransitionView -(void)initMTransitionView{ for (UIView *tmp in self.view.subviews) { [tmp removeFromSuperview]; [self.mTransitionView addSubview:tmp]; } [self.view addSubview:self.mTransitionView]; } #pragma mark 拖動(dòng)手勢(shì)動(dòng)作 -(void)panAction:(UIPanGestureRecognizer*)pan{ CGPoint location = [pan translationInView:pan.view.superview]; CGPoint center = self.mTransitionView.center; if (pan.state==UIGestureRecognizerStateEnded) { if (center.x<_centerMaxX*0.5+DEVICE_W*0.25){ [self closeMenu]; }else{ [self openMenu]; } }else if(pan.state==UIGestureRecognizerStateChanged){ if (location.x<0) {//向左滑 center.x = center.x+location.x<=DEVICE_W/2? DEVICE_W/2 : center.x+location.x; }else{ center.x = center.x+location.x>=_centerMaxX? _centerMaxX : center.x+location.x; } self.mTransitionView.center = center; [pan setTranslation:CGPointMake(0, 0) inView:pan.view.superview]; } } #pragma mark 添加手勢(shì) -(void)addGestureForMTransitionView{ UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)]; [_mTransitionView addGestureRecognizer:pan]; _mTapGester = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)]; } #pragma mark--懶加載 -(UIView *)mTransitionView{ if (_mTransitionView==nil) { _mTransitionView = [[UIView alloc]initWithFrame:self.view.bounds]; } return _mTransitionView; } -(void)tapAction{ CGFloat x = _mTransitionView.center.x; if (x>=_centerMaxX) { [self closeMenu]; } } @end
感謝各位的閱讀!關(guān)于“iOS中如何仿QQ實(shí)現(xiàn)側(cè)滑菜單功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站aaarwkj.com,海內(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)景需求。
標(biāo)題名稱:iOS中如何仿QQ實(shí)現(xiàn)側(cè)滑菜單功能-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)路徑:http://aaarwkj.com/article20/ccheco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)、外貿(mào)建站、品牌網(wǎng)站制作、域名注冊(cè)、網(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)容