天天看點

iOS好用的第三方側邊欄控件——MMDrawerController(二)

三、關于MMDrawerController的子類

       開發者如果有特殊的需求,也可以通過繼承MMDrawerController來實作自己的側邊欄控制器類,MMDrawerController架構中提供了一個擴充,在編寫MMDrawerController時,開發者可以導入MMDrawerController+Subclass.h檔案,這個檔案中提供了許多控制器的監聽方法供開發者重寫,解析如下:

//出現單擊手勢會回調的方法 如果要重寫 必須調用父類的此方法

-(void)tapGestureCallback:(UITapGestureRecognizer *)tapGesture __attribute((objc_requires_super));

//出現滑動手勢會回調的方法 如果要重寫 必須調用父類的此方法

-(void)panGestureCallback:(UIPanGestureRecognizer *)panGesture __attribute((objc_requires_super));

//決定是否響應某個手勢

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch __attribute((objc_requires_super));

//準備展示側邊欄時調用的方法

-(void)prepareToPresentDrawer:(MMDrawerSide)drawer animated:(BOOL)animated __attribute((objc_requires_super));

//關閉側邊欄時調用的方法

-(void)closeDrawerAnimated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion __attribute((objc_requires_super));

//打開側邊欄時調用的方法

-(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion __attribute((objc_requires_super));

//裝置旋轉方向時調用的方法

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration __attribute((objc_requires_super));

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration __attribute((objc_requires_super));

四、一些輔助類

       MMDrawerController架構中還提供了一個MMDrawerBarButtonItem的輔助類,這個類可以建立三道杠的菜單按鈕。其中方法如下:

//初始化方法

-(id)initWithTarget:(id)target action:(SEL)action;

//擷取某個狀态下的按鈕顔色

-(UIColor *)menuButtonColorForState:(UIControlState)state __attribute__((deprecated("Use tintColor instead")));

//設定某個狀态的按鈕顔色

-(void)setMenuButtonColor:(UIColor *)color forState:(UIControlState)state __attribute__((deprecated("Use tintColor instead")));

MMDrawerBarButtonItem繼承自UIBarButtonItem,可以直接在導航欄上使用。

       前面有提到,側邊欄的展現動畫開發者可以進行自定義,為了使開發者在使用MMDrawerController時更加友善,MMDrawerController架構中還提供了一個動畫輔助類MMDrawerVisualState,這個類中封裝好了許多動畫效果,開發者可以直接使用,示例如下:

//使用提供的動畫模闆

[rootController setDrawerVisualStateBlock:[MMDrawerVisualState slideAndScaleVisualStateBlock]];

MMDrawerVisualState中所提供的動畫模闆列舉如下:

//從後向前漸現

+(MMDrawerControllerDrawerVisualStateBlock)slideAndScaleVisualStateBlock;

//滑動漸現

+(MMDrawerControllerDrawerVisualStateBlock)slideVisualStateBlock;

//立方動畫

+(MMDrawerControllerDrawerVisualStateBlock)swingingDoorVisualStateBlock;

//視差動畫

+(MMDrawerControllerDrawerVisualStateBlock)parallaxVisualStateBlockWithParallaxFactor:(CGFloat)parallaxFactor;

五、MMDrawerController無法完成的需求

       為了確定MMDrawerController庫的輕量級,其作者在設計時也做了功能上的取舍權衡,MMDrawerController無法完成以下需求:

1.上邊欄與下邊欄。

2.同時展示左邊欄與又邊欄。

3.無法設定顯示一個最小的抽屜寬度。

4.不能支援UITabBarController容器。

5.不能在中心視圖控制器之上呈現側邊欄視圖。

繼續閱讀