標籤:ios側邊欄菜單解決方案 ios左右側欄 ios中左右兩側導覽列的簡單實現 ios 側邊欄菜單 ios 側邊欄菜單實現
這是一個仿照網易用戶端側欄效果(demo),用最簡單的方法實現,以下只是一部分代碼:有興趣的同學可以到gitHub下載,:demo
#import "ViewController.h"
#import "BSYItem.h"
#import "BSYView.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"首頁";
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bar"] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:NSForegroundColorAttributeName];
// 左側按鈕
self.left = [[BSYItem alloc]init];
self.navigationItem.leftBarButtonItem = [self.left addLeft];
self.left.left.selected = NO;
[self.left .left addTarget:self action:@selector(leftclick:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)leftclick:(UIButton *)button
{
self.left.left.selected =! button.selected;
if (self.left.left.selected==YES) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationsEnabled:YES];
self.slide.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width/4, [UIScreen mainScreen].bounds.size.height);
[UIView commitAnimations];
}else{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationsEnabled:YES];
self.slide.frame = CGRectMake(0, 0, 0, [UIScreen mainScreen].bounds.size.height);
[UIView commitAnimations];
}
[self addbuttonClick];
}
下載代碼:BSYTheSideBar
iOS 仿照網易側欄效果demo