【代码笔记】iOS-侧滑效果
来源:互联网 发布:aliasstudio软件下载 编辑:程序博客网 时间:2024/06/03 21:00
一,效果图。
二,工程图。
三,代码。
AppDelegate.h
#import <UIKit/UIKit.h>//加入头文件#import "PPRevealSideViewController.h"@interface AppDelegate : UIResponder <UIApplicationDelegate,PPRevealSideViewControllerDelegate>@property (strong, nonatomic) UIWindow *window;@end
AppDelegate.m
#import "AppDelegate.h"#import "MainViewController.h"@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. MainViewController *main = [[MainViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main]; PPRevealSideViewController *revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav]; revealSideViewController.delegate = self; self.window.rootViewController = revealSideViewController; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES;}
MainViewController.h
#import <UIKit/UIKit.h>@interface MainViewController : UIViewController@end
MainViewController.m
#import "MainViewController.h"//加入头文件#import "PPRevealSideViewController.h"#import "leftViewController.h"#import "rightViewController.h"@interface MainViewController ()@end@implementation MainViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //设置背景色 self.view.backgroundColor= [UIColor orangeColor]; //隐藏导航条 self.navigationController.navigationBarHidden=YES; // 手势左右滑动屏幕 UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleMoveFrom:)]; [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; [self.view addGestureRecognizer:swipeLeft]; UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleMoveFrom:)]; [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; [self.view addGestureRecognizer:swipeRight]; }// 滑动事件-(void)handleMoveFrom:(UISwipeGestureRecognizer *)swipe{ if(swipe.direction == UISwipeGestureRecognizerDirectionRight){ leftViewController *left = [[leftViewController alloc] init]; [self.revealSideViewController pushViewController:left onDirection:PPRevealSideDirectionLeft withOffset:50.0 animated:YES]; } if(swipe.direction == UISwipeGestureRecognizerDirectionLeft){ rightViewController *right = [[rightViewController alloc] init]; [self.revealSideViewController pushViewController:right onDirection:PPRevealSideDirectionRight withOffset:50.0 animated:YES]; }}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
rightViewController.h
#import <UIKit/UIKit.h>@interface rightViewController : UIViewController@end
rightViewController.m
#import "rightViewController.h"@interface rightViewController ()@end@implementation rightViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //设置标题 self.title=@"right"; //设置背景色 self.view.backgroundColor=[UIColor blueColor];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
leftViewController.h
#import <UIKit/UIKit.h>@interface leftViewController : UIViewController@end
leftViewController.m
#import "leftViewController.h"@interface leftViewController ()@end@implementation leftViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //设置标题 self.title=@"left"; //设置背景色 self.view.backgroundColor=[UIColor redColor]; }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
0 0
- 【代码笔记】iOS-侧滑效果
- 【代码笔记】iOS-水波效果
- iOS 水纹效果代码笔记
- 【代码笔记】iOS-抽屉效果的实现
- 【代码笔记】iOS-淡出淡入效果
- 【代码笔记】iOS-翻页效果的实现
- 【代码笔记】iOS-文字走马灯效果
- 【代码笔记】iOS-DropDownDemo-下拉按钮效果
- 【代码笔记】iOS-翻书效果的实现
- 【代码笔记】iOS-给UIImageView加上圆角效果
- 【代码笔记】iOS-利用图片序列创建动态图片效果
- 【代码笔记】iOS-UIView的placeholder的效果
- 【代码笔记】iOS-页面之间的跳转效果
- IOS笔记UI--侧滑效果的实现
- IOS笔记UI--侧滑效果的实现(二)抽屉效果
- IOS 代码生成马赛克效果
- iOS侧滑效果Demo
- jquery学习笔记-效果代码
- CART回归树&模型树 生成 剪枝 in Python
- 如何看代码的架构
- A-8 8 Which of these appropriately describes the results of a manual SQL Tuning Advisor task? A. A l
- iOS开发-UI控件:修改textField的placeholder的字体颜色、大小
- 第四周 项目六 多项式求和
- 【代码笔记】iOS-侧滑效果
- 第十二周项目五:迷宫问题之深度优先遍历解法
- iOS开发-进阶:发布 在企业内部分发 iOS 应用程序
- 发散思维考虑编码流程
- 9 To view the results of a manual SQL Tuning Advisor task, which steps should the DBA take? A. From
- 1222: [HNOI2001]产品加工
- 第十四周项目1 折半查找
- 第十五周--项目4算法验证希尔排序
- iOS开发-进阶:企业应用发布教程