【代碼筆記】翻頁效果的實現,代碼筆記翻頁
一,。
二,工程圖。
三,代碼。
RootViewController.h
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController@end
RootViewController.m
#import "RootViewController.h"#import "FirstViewController.h"@interface RootViewController ()@end@implementation RootViewController- (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 redColor]; self.title=@"root"; }-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //點擊root,也就是紅色的任何處,頁面會像翻書一樣翻轉。翻轉到first,也就是藍色的介面。當點擊頂部root頁面部分的時候,頁面會重新翻到root,也就是紅色的介面。 FirstViewController *firstView=[[FirstViewController alloc]init]; UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:firstView]; nav.modalTransitionStyle=UIModalTransitionStylePartialCurl; [self.navigationController presentViewController:nav animated:YES completion:nil];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
FirstViewController.h
#import <UIKit/UIKit.h>@interface FirstViewController : UIViewController@end
FirstViewController.m
#import "FirstViewController.h"@interface FirstViewController ()@end@implementation FirstViewController- (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 blueColor]; self.title=@"first";}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}