ios左右側(cè)滑框架匯總

其實(shí)這種開(kāi)源框架github上已經(jīng)好多好多了,但是總是沒(méi)找到適合自己的,找了好久才找到。(我的要求,即可以左右滑動(dòng),也可以點(diǎn)擊滑動(dòng),并且可拓展性好。)下面總結(jié)兩種,也是我自己用的。

1.IIViewDeckController,這是我在下載ShareSDK的時(shí)候,發(fā)現(xiàn)他的demo里用的這種,感覺(jué)很不錯(cuò),擠拿過(guò)來(lái)用了。

在AppDelegate.m中

#import "CenterViewController.h"    //中間的視圖控制器
#import "LeftViewController.h"        //左邊的視圖控制器
#import "RightViewController.h"     //右邊的視圖控制器


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    CenterViewController *centerVC  = [[CenterViewController alloc] init];
    UINavigationController *centerNav = [[UINavigationController alloc] initWithRootViewController:centerVC];
    
    LeftViewController *leftVC      = [[LeftViewController alloc] init];
    RightViewController *rightVC    = [[RightViewController alloc] init];
    
    self.viewController = [[IIViewDeckController alloc] initWithCenterViewController:centerNav leftViewController:leftVC rightViewController:rightVC];//可以只添加左邊,也可以只添加右邊,具體看里面的代碼
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    self.window.rootViewController = self.viewController;
    
    [self.window makeKeyAndVisible];
    return YES;
}

在CenterViewController.m中

- (void)viewDidLoad
{
    [super viewDidLoad];
        
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [rightBtn setTitle:@"right" forState:UIControlStateNormal];
    rightBtn.frame = CGRectMake(0.0, 0.0, 53.0, 30.0);
    [rightBtn addTarget:self action:@selector(rightButtonClickHandler:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
}

-(void)rightButtonClickHandler:(UIButton *)button
{
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [app.viewController toggleRightViewAnimated:YES];
}

2.叫MKDSlideViewController
在AppDelegate.m中

//MainViewController為UITabBarControllers,里面放了viewControllers

    MainViewController *main = [[MainViewController alloc] init];
    LeftViewController *left = [[LeftViewController alloc] init];
    RightViewController *right = [[RightViewController alloc] init];
    
    _slideViewController = [[MKDSlideViewController alloc] initWithMainViewController:main];
    _slideViewController.leftViewController = left;
    _slideViewController.rightViewController = right;
    
    self.window.rootViewController = self.slideViewController;

在控制器的.m文件中

- (void)viewDidLoad
{
    [super viewDidLoad];

    //
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, 44, 44);
    [leftBtn setTitle:@"左" forState:UIControlStateNormal];
    [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftItemClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
}

#pragma mark - Action Methods
//這里用的是通知
-(void)leftItemClick
{
    [[NSNotificationCenter defaultCenter] postNotificationName:kShowLeftControllertNotification object:nil];
}

具體的源碼github里可以自己下載。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容