iOS入门之page平铺导航,scrollerview滚动计算和pager的切换
来源:互联网 发布:张伯伦场均数据 编辑:程序博客网 时间:2024/06/06 17:21
scrollview滚动计算和UIpagerControl可以做出类似于android的引导页效果,
scrollview可以水平滚动,也可以垂直滚动,很方便
记得实现协议:
#import <UIKit/UIKit.h>@interface ViewController : UIViewController <UIScrollViewDelegate>@end
主要的代码和注释如下:
#import "ViewController.h"@interface ViewController ()@property (strong,nonatomic) UIView *page1;@property (strong,nonatomic) UIView *page2;@property (strong,nonatomic) UIView *page3;@property (weak, nonatomic) IBOutlet UIScrollView *scrollerView;@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;- (IBAction)changePage:(id)sender;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; CGFloat scrollViewHeight = self.scrollerView.frame.size.height; CGFloat scrollViewWidth = self.view.frame.size.width; //滚动的方向,滚动的距离总的是三个父控件的宽度和一个自己的高度,即为只有横向的滚动,纵向不滚动 self.scrollerView.contentSize = CGSizeMake(scrollViewWidth * 3, scrollViewHeight); /*self.view.frame.size.height- self.pageControl.frame.size.height - self.tabBarController.view.frame.size.height*/ self.scrollerView.frame = self.view.frame; UIStoryboard *mainBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *page1Controller = [mainBoard instantiateViewControllerWithIdentifier:@"page1"]; self.page1 = page1Controller.view; self.page1.frame = CGRectMake(0.0f, 0.0f, scrollViewWidth, scrollViewHeight); UIViewController *page2Controller = [mainBoard instantiateViewControllerWithIdentifier:@"page2"]; self.page2 = page2Controller.view; self.page2.frame = CGRectMake(scrollViewWidth, 0.0f, scrollViewWidth, scrollViewHeight); UIViewController *page3Controller = [mainBoard instantiateViewControllerWithIdentifier:@"page3"]; self.page3 = page3Controller.view; self.page3.frame = CGRectMake(2 * scrollViewWidth, 0.0f, scrollViewWidth, scrollViewHeight); self.scrollerView.delegate = self; //添加子view [self.scrollerView addSubview:self.page1]; [self.scrollerView addSubview:self.page2]; [self.scrollerView addSubview:self.page3]; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (IBAction)changePage:(id)sender { [UIView animateWithDuration:0.3f animations:^{ NSInteger whichPage = self.pageControl.currentPage; self.scrollerView.contentOffset = CGPointMake(self.view.frame.size.width*whichPage, 0.0f); }];}//scrollview滚动事件-(void)scrollViewDidScroll:(UIScrollView *)aScrollView{ CGPoint offset = aScrollView.contentOffset; self.pageControl.currentPage = offset.x/320.0f;}@end
0 0
- iOS入门之page平铺导航,scrollerview滚动计算和pager的切换
- iOS开发那些事-平铺导航-基于Page的导航及案例实现
- IOS学习之——导航3 平铺导航1:实现基于分屏的平铺导航
- iOS scrollerView 滚动 工具类
- IOS 入门开发之导航栏按钮切换(三)
- IOS 入门开发之导航栏按钮切换
- ios ScrollerView之图片轮播器
- ios-使用平铺导航模式
- 导航 滚动切换
- iOS imageView 的平铺
- Objective-C之平铺导航、标签导航、树形结构导航
- iOS开发之 背景平铺
- iOS基础之图片平铺
- Unity3D背景图片滚动效果和纹理平铺
- 使用 ScrollerView 实现 可上下滚动的分类栏
- 页面滚动的时候自动切换导航栏
- ScrollerView上面加导航控制器
- iOS-UI效果之【监听滚动导航条渐隐】
- Android ShareSdk 微信分享的步骤
- 纯代码实现布局的UIViewController跳转到带storyboard布局的UIViewController
- Java大数处理
- 第一行代码总结:10网络:10.3解析XML格式数据:
- iOS开发 音频播放、录音、视频播放、拍照、视频录制
- iOS入门之page平铺导航,scrollerview滚动计算和pager的切换
- 如何控制打印Logcat打印信息?封装Logcat的简单工具类就可以了
- mysql分页丢数据的分析
- Linux 时钟和ntp服务
- 第一行代码总结:10网络:10.3.2 SAX解析方式
- 为什么接口中变量要用final修饰
- RPG Maker MV之如何创建NPC
- 安卓 dex 通用脱壳技术研究
- iOS开发 - 处理不等高TableViewCell的招术