RESideMenu是一個抽屜效果的第三方,實現(xiàn)原理為RESideMenu作為一個視圖控制器,依次添加子視圖左側(cè)菜單欄控制器和內(nèi)容頁控制逗威,通過pan手勢識別蚌讼,來縮放內(nèi)容控制頁辟灰,從而來顯示左側(cè)菜單欄。
1.使用
?UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[DEMOFirstViewController alloc] init]];? ? DEMOLeftMenuViewController *leftMenuViewController = [[DEMOLeftMenuViewController alloc] init];? ?
DEMORightMenuViewController *rightMenuViewController = [[DEMORightMenuViewController alloc] init];?? ??
? RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:navigationController? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? leftMenuViewController:leftMenuViewController?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? rightMenuViewController:rightMenuViewController];
2.結(jié)構(gòu)
1)調(diào)用方法
- (id)initWithContentViewController:(UIViewController *)contentViewController?? ? ? ? ? ? leftMenuViewController:(UIViewController *)leftMenuViewController? ? ? ? ? ? rightMenuViewController:(UIViewController *)rightMenuViewController;
===>2)調(diào)用 init 進行初始化?
=====>3)?- (void)viewDidLoad篡石;(核心代碼)
//加背景圖
//在vc中加入view ?menuViewContainer
//在vc中加入view ?contentViewContaine
//如果有l(wèi)efMenuVC
//把leftMenuVC設(shè)置成本VC的子控制器
?[self addChildViewController:self.leftMenuViewController]; ? ? ??
//把lefmenuVC的view加入到self.menuViewContainer
[self.menuViewContainer addSubview:self.leftMenuViewController.view]; ? ? ? ?
//再把contentViewController設(shè)置成本VC的子控制器
[self addChildViewController:self.contentViewController]; ??
//把contentVC的view加入到contentviewContainer中
[self.contentViewContainer addSubview:self.contentViewController.view]; ? ?
//設(shè)置menuviewContainer的透明度
self.menuViewContainer.alpha = !self.fadeMenuView ?: 0;? ?
//設(shè)置動畫效果
//設(shè)置手勢 panGesture
[self updateContentViewShadow];
3.展示抽屜效果
使用CGAffineTransform來進行縮放
分別對backgroundImageView??menuViewContainer?contentViewContainer 進行縮放?
?self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue);
另外:? [self.leftMenuViewController beginAppearanceTransition:YES animated:YES];
Tells a child controller its appearance is about to change.If you are implementing a custom container controller, use this method to tell the child that its views are about to appear or disappear. Do not invoke?viewWillAppear:,?viewWillDisappear:,?viewDidAppear:, or?viewDidDisappear:?directly.
beginAppearanceTransition :告訴這個子vc芥喇,它將要現(xiàn)實顯示或者消失,將自動調(diào)用viewWillAppear凰萨,viewWillDisappear乃坤,viewDidAppear,viewDidDisappear
第二點:在contentViewContainer加入btn沟蔑,為了點擊contentViewContationer隱藏左側(cè)菜單欄
4.panGesture手勢
調(diào)用uigestureRecognizer的代理
1)
首先 根據(jù)- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch湿诊;判斷對這個手勢該不該做進一步相應(yīng)(左側(cè)菜單欄是否隱藏&&pan手勢&&point的x值在屏幕兩側(cè)20px以內(nèi))
2)Pan gesture recognizer
recognizer.state == UIGestureRecognizerStateBegan
此時內(nèi)容頁的frame沒有改變,contentbutton添加到根視圖的最上層
3)recognizer.state == UIGestureRecognizerStateChanged
根據(jù)手勢的point來更改視圖的大小
self.backgroundImageView.transform = CGAffineTransformMakeScale(backgroundViewScale, backgroundViewScale);
參考:http://www.cnblogs.com/ios-wmm/p/4276746.html
CoreGraphics框架中的CGAffineTransform類可用于設(shè)定UIView的transform屬性瘦材,控制視圖的縮放厅须、旋轉(zhuǎn)和平移操作:
另稱放射變換矩陣,
總得來說食棕,這個類中包含3張不同類型朗和,分別使用如下3個方法創(chuàng)建數(shù)值;
1.CGAffineTransformMakeTranslation(CGFloattx,CGFloatty)(平移:設(shè)置平移量)
2.CGAffineTransformMakeScale(CGFloatsx,CGFloatsy)(縮放:設(shè)置縮放比例)僅通過設(shè)置縮放比例就可實現(xiàn)視圖撲面而來和縮進頻幕的效果簿晓。
3.CGAffineTransformMakeRotation(CGFloatangle)(旋轉(zhuǎn):設(shè)置旋轉(zhuǎn)角度)
以上3個都是針對視圖的原定最初位置的中心點為起始參照進行相應(yīng)操作的眶拉,在操作結(jié)束之后可對設(shè)置量進行還原:
view.transform=CGAffineTransformIdentity;
另外還可以通過CGAffineTransformTranslate等方法對現(xiàn)有的transform進行進一步處理;
更多了解core animation ? =====》》》 https://github.com/yixiangboy/IOSAnimationDemo