博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS:翻页效果
阅读量:6577 次
发布时间:2019-06-24

本文共 5017 字,大约阅读时间需要 16 分钟。

 

////  main.m//  Hello////  Created by lishujun on 14-8-28.//  Copyright (c) 2014年 lishujun. All rights reserved.////  翻页太快会有问题,未解决//Unbalanced calls to begin/end appearance transitions for 
.#import
// -----------------------------内容视图控制器-----------------------------@interface ContentViewControler : UIViewController@property (nonatomic,strong) UILabel *label;@property NSString *message;@end@implementation ContentViewControler@synthesize label ;@synthesize message = _message;-(id)initWithMessage:(NSString *)aMessage{ _message = aMessage; return self;}-(void) viewDidLoad{ //[super viewDidLoad]; //创建label对象 label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)]; label.text = _message; label.center = self.view.center; label.textAlignment = UITextAlignmentCenter; label.backgroundColor = [UIColor clearColor]; label.textColor = [UIColor redColor]; //在视图上添加label [self.view addSubview:label]; self.view.backgroundColor = [UIColor lightGrayColor];}-(void) updateMessage:(NSString*)aMessage{ _message = aMessage; label.text = _message;}@end// -----------------------------视图控制器对象-----------------------------@interface MyPageViewController : UIViewController
{ int pageIndex;}@property (strong, nonatomic) UIPageViewController *pageViewControler;@property (strong, nonatomic) NSArray *array;@end@implementation MyPageViewController@synthesize pageViewControler = _pageViewControler;@synthesize array = _array;-(void) viewDidLoad{ [super viewDidLoad]; self.view.frame = CGRectMake(0.0f, 0.0f, 320.0f, 440.0f); ContentViewControler *content1 = [[ContentViewControler alloc]initWithMessage:@"Hello"]; ContentViewControler *content2 = [[ContentViewControler alloc]initWithMessage:@""]; NSArray *array = @[content1]; NSLog(@"%@",content1); _array = [[NSArray alloc]initWithObjects:content1, content2, nil]; _pageViewControler = [[UIPageViewController alloc] initWithTransitionStyle: UIPageViewControllerTransitionStylePageCurl navigationOrientation: UIPageViewControllerNavigationOrientationHorizontal options: nil]; [_pageViewControler setViewControllers:array direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL]; _pageViewControler.dataSource = self; [self addChildViewController:_pageViewControler]; [self.view addSubview:_pageViewControler.view]; pageIndex = 0;}//--------------- data source 方法 ------------------ (UIViewController *) pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{ ContentViewControler *aViewController = (ContentViewControler*)[self changeViewControler:viewController]; [aViewController updateMessage:@"i'm lishujun too"]; return aViewController;}- (UIViewController *) pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{ ContentViewControler *aViewController = (ContentViewControler*)[self changeViewControler:viewController]; [aViewController updateMessage:@"i'm lishujun"]; return aViewController;}// --- 自定义方法,在只有两个元素的数组里切换元素----(UIViewController *) changeViewControler:(UIViewController*)viewController{ int index = [_array indexOfObject:viewController]; switch(index) { case 0: return _array[1]; case 1: return _array[0]; } return nil;}@end// -----------------------------委托对象-------------------------------@interface HelloWorldAppDelegate : NSObject
{ IBOutlet UIWindow *window;}@property (nonatomic, retain) UIWindow *window;@property (nonatomic, retain) MyPageViewController *viewController;@property (nonatomic, retain) UINavigationController *nav;@end@implementation HelloWorldAppDelegate@synthesize window;@synthesize viewController;-(void) applicationDidFinishLaunching:(UIApplication *)application{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]]; self.viewController = [[MyPageViewController alloc]init]; //self.window.rootViewController = self.viewController; self.nav = [[UINavigationController alloc]initWithRootViewController: viewController]; [self.nav setNavigationBarHidden:YES]; //隐藏导航栏,位于视图顶部 [self.nav setToolbarHidden:YES]; //隐藏工具栏,位于视图底部 self.window.rootViewController = self.nav; [self.window makeKeyAndVisible];}@end// -----------------------------程序入口-----------------------------int main(int argc, char * argv[]){ @autoreleasepool { return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate"); }}

 

转载于:https://www.cnblogs.com/code-style/p/3972857.html

你可能感兴趣的文章
cocos creator destroy方法
查看>>
第二课 HTML+CSS
查看>>
time random sys os模块
查看>>
第一章 台达组态软件的基本介绍
查看>>
DOM_04之常用对象及BOM
查看>>
LOJ#2085 循环之美
查看>>
Leetcode | Longest Common Prefix
查看>>
Filter实现用户自动登录
查看>>
第十九天笔记
查看>>
发送json给服务器
查看>>
日历控件datetimepicker(IE11)
查看>>
RH253读书笔记(5)-Lab 5 Network File Sharing Services
查看>>
CCNP路由实验(4) -- BGP
查看>>
图像卷积与滤波的一些知识点
查看>>
关于 tchart 控件的相关内容
查看>>
(转)新的挑战:敏捷开发与优秀的程序员
查看>>
JS xpath
查看>>
关于 spring MVC 配置自动扫描中 use-default-filters 属性
查看>>
LIUNX 安装 nginx
查看>>
table头部固定,内容滚动
查看>>