国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

左右側滑菜單功能的實現

2019-11-14 18:33:20
字體:
來源:轉載
供稿:網友

左右側滑功能是比較常見的效果,此實例實現如下的效果:

這邊使用到的SlideNavigationController開源類(引入源代碼中的Source),其為NavigationController子類,在運用程序AppDelegate就設置為其根視圖;主要代碼如下:

1:AppDelegate主要代碼如下:

#import "AppDelegate.h"#import "SlideNavigationController.h"#import "leftViewController.h"#import "rightViewController.h"#import "ViewController.h"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    self.window.backgroundColor = [UIColor whiteColor];    
//設置根導航視圖 ViewController
*homeVc = [[ViewController alloc] init]; [self.window setRootViewController:[[SlideNavigationController alloc] initWithRootViewController:homeVc]];
//設置左右視圖 leftViewController
* leftController=[[leftViewController alloc]init]; rightViewController* rightController=[[rightViewController alloc]init]; [SlideNavigationController sharedInstance].rightMenu = rightController; [SlideNavigationController sharedInstance].leftMenu = leftController; [SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18; [self.window makeKeyAndVisible]; return YES;}

2:主頁面ViewController代碼:

#import <UIKit/UIKit.h>#import "SlideNavigationController.h"@interface ViewController : UIViewController<SlideNavigationControllerDelegate>@end
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];        self.view.backgroundColor=[UIColor yellowColor];        self.title=@"首頁";        UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];    [button setTitle:@"右邊" forState:UIControlStateNormal];    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];    [button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside];    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];    [SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem;}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}#PRagma mark - SlideNavigationController Methods -- (BOOL)slideNavigationControllerShouldDisplayLeftMenu{    return YES;}- (BOOL)slideNavigationControllerShouldDisplayRightMenu{    return YES;}@end

注意要實現SlideNavigationControllerDelegate的兩個是否有左跟右的菜單,還可以設置其導航欄的按鍵樣式,如果沒有設置會像左邊出現的這種默認的;

3:左邊視圖leftViewController

#import <UIKit/UIKit.h>#import "SlideNavigationController.h"#import "OneViewController.h"#import "TwoViewController.h"@interface leftViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>@end
#import "leftViewController.h"@interface leftViewController()@property(nonatomic,strong)UITableView *tableView;@property(strong,nonatomic) NSArray *listData;

@property(assign,nonatomic) bool slideOutAnimationEnabled;
@end@implementation leftViewController-(void)viewDidLoad{    [super viewDidLoad];    self.view.backgroundColor=[UIColor redColor];        [self ininLoadTable];}-(void)ininLoadTable{    self.tableView=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];    self.tableView.delegate=self;    self.tableView.dataSource=self;       [self.view addSubview:self.tableView];        self.listData=[[NSArray alloc] initWithObjects:@"朋友圈",@"個人好友",@"最近聯系人", nil];}#pragma mark - UITableView Delegate & Datasrouce -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return self.listData.count;}- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 20)];    view.backgroundColor = [UIColor clearColor];    return view;}- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{    return 20;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];    if (cell==nil) {        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];    }    cell.textLabel.text=self.listData[indexPath.row];        cell.backgroundColor = [UIColor clearColor];        return cell;}//跳轉- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    UIViewController *vc ;        switch (indexPath.row)    {        case 0:            vc = [[OneViewController alloc]init];            break;                    case 1:            vc = [[TwoViewController alloc]init];            break;                    case 2:            vc = [[OneViewController alloc]init];            break;                    case 3:            [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];            [[SlideNavigationController sharedInstance] popToRootViewControllerAnimated:YES];            return;            break;    }        [[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:vc                                                             withSlideOutAnimation:self.slideOutAnimationEnabled                                                                     andCompletion:nil];}@end

注意:這邊主要是進行導航跳轉時要注意,popToRootViewControllerAnimated跟popToRootAndSwitchToViewController

4:右邊的rightViewController

#import "rightViewController.h"@implementation rightViewController-(void)viewDidLoad{    [super viewDidLoad];    self.view.backgroundColor=[UIColor blueColor];}@end

 

附:另外二個插件也實現更好的效果,地址如下(https://github.com/JVillella/JVFloatingDrawer)效果圖如下:

 另一個地址如下:(https://github.com/hujewelz/HUSliderMenu)效果圖如下:

源代碼下載地址:左右側滑菜單源代碼


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 四子王旗| 元谋县| 阿拉善右旗| 海兴县| 通州区| 南充市| 陕西省| 苏尼特左旗| 益阳市| 勃利县| 新津县| 山东| 榕江县| 石渠县| 库尔勒市| 巨野县| 浠水县| 辽宁省| 平顺县| 襄城县| 卓资县| 桃源县| 中西区| 普陀区| 汝阳县| 德保县| 惠来县| 凤山市| 长丰县| 泰顺县| 武汉市| 滨州市| 巢湖市| 吴忠市| 东莞市| 宜兰县| 仙居县| 高雄市| 阿鲁科尔沁旗| 沧源| 柳江县|