效果圖
demo地址在文章最后
使用說(shuō)明
空白menu,給menu添加子控件可通過(guò)代理方法
將SLSlideMenu文件夾拖入項(xiàng)目
調(diào)用
1> #import "SLSlideMenu.h"
2> [SLSlideMenu slideMenuWithFrame:self.view.frame
delegate:self
direction:SLSlideMenuDirectionLeft
slideOffset:250
allowSwipeCloseMenu:YES
aboveNav:YES
identifier:@"left"];
或者在viewdidload中:
[SLSlideMenu prepareSlideMenuWithFrame:self.view.frame
delegate:self
direction:SLSlideMenuSwipeDirectionLeft
slideOffset:300
allowSlideMenuSwipeShow:YES
allowSwipeCloseMenu:YES
aboveNav:YES
identifier:@"swipeLeft"];
自定義menu子控件:
1> 遵守協(xié)議<SLSlideMenuProtocol>
2> 實(shí)現(xiàn)代理方法:將子控件添加到menuView
- (void)slideMenu:(SLSlideMenu *)slideMenu prepareSubviewsForMenuView:(UIView *)menuView {
UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 100, 30)];
lb.text = @"自定義控件";
lb.font = [UIFont systemFontOfSize:12];
lb.textColor = [UIColor darkGrayColor];
[menuView addSubview:lb];
}
在自定義子控件時(shí)
如果一個(gè)方向只有一個(gè)彈窗可根據(jù)direction區(qū)分menu
if (slideMenu.direction == SLSlideMenuDirectionTop) {
UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 100, 30)];
lb.text = @"自定義控件1";
lb.font = [UIFont systemFontOfSize:12];
lb.textColor = [UIColor darkGrayColor];
[menuView addSubview:lb];
}
if (slideMenu.direction == SLSlideMenuDirectionBottom) {
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(70, 200, 100, 40)];
btn.backgroundColor = [UIColor purpleColor];
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:btn];
}
如果一個(gè)方向有多個(gè)彈窗,可設(shè)置identifier來(lái)區(qū)分menu
if ([slideMenu.identifier isEqualToString:@"left"]) {
menuView.backgroundColor = [UIColor yellowColor];
}
if ([slideMenu.identifier isEqualToString:@"swipeLeft"]) {
menuView.backgroundColor = [UIColor greenColor];
}
接口說(shuō)明
1> 點(diǎn)擊彈出的場(chǎng)景
/**
* 創(chuàng)建menu視圖隆檀。此方式一般用在點(diǎn)擊彈出的場(chǎng)景恐仑,不支持手勢(shì)滑出。
*param frame 如果不要蓋住nav 就傳self.view.frame裳仆;如果要蓋住nav就傳CGRectMake(0, 64, screenW, screenH)
*param delegate 代理 可通過(guò)設(shè)置代理來(lái)配置menu的子控件
*param direction menu彈出方位歧斟。SLSlideMenuSwipeDirectionRight代表從右邊彈出
*param slideOffset menu的寬度/高度
*param allowSwipeCloseMenu 是否允許手勢(shì)關(guān)閉
*param aboveNav 是否蓋住nav
*param identifier 標(biāo)識(shí)符 可以通過(guò)設(shè)置進(jìn)行唯一標(biāo)識(shí)
*/
+ (void)slideMenuWithFrame:(CGRect)frame
delegate:(id <SLSlideMenuProtocol> )delegate
direction:(SLSlideMenuDirection)direction
slideOffset:(CGFloat)slideOffset
allowSwipeCloseMenu:(BOOL)isAllow
aboveNav:(BOOL)isAbove
identifier:(NSString * )identifier;
2> 手勢(shì)滑出的場(chǎng)景
/**
* 配置menu視圖∫耗希可在viewdidload中,此種方式可通過(guò)左滑右滑手勢(shì)呼出滑凉。
*param frame 如果不要蓋住nav 就傳self.view.frame;如果要蓋住nav就傳CGRectMake(0, 64, screenW, screenH)
*param delegate 代理 可通過(guò)設(shè)置代理來(lái)配置menu的子控件
*param direction 手勢(shì)滑出方位咒钟。SLSlideMenuSwipeDirectionRight代表從右邊滑出
*param slideOffset menu的寬度/高度
*param allowSlideMenuSwipeShow 是否允許手勢(shì)滑出
*param allowSwipeCloseMenu 是否允許手勢(shì)關(guān)閉
*param aboveNav 是否蓋住nav
*param identifier 標(biāo)識(shí)符 可以通過(guò)設(shè)置進(jìn)行唯一標(biāo)識(shí)
*/
+ (void)prepareSlideMenuWithFrame:(CGRect)frame
delegate:(id <SLSlideMenuProtocol> )delegate
direction:(SLSlideMenuSwipeDirection)direction
slideOffset:(CGFloat)slideOffset
allowSlideMenuSwipeShow:(BOOL)isAllowSwipeShow
allowSwipeCloseMenu:(BOOL)isAllowSwipeCloseMenu
aboveNav:(BOOL)isAbove
identifier:(NSString *)identifier;
github 地址 SLSlideMenu
如果覺(jué)得好用記得星星鼓勵(lì)~