IOS开发UI阶段 第六周
2015-08-20 08:59
585 查看
8月13日
自习一天,复习UI前面的课程
8月14日
单元格的复用、单元格的常用属性、辅助图标、自适应高度
8月15日
单元格的定制的三种方法
8月16日
做课后作业,自习
8月17日
触摸与手势
8月18日
UIScrollView
综合性的示例:模拟相册
重要代码:
1、在根视图控制中:
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//设置视图控制器的滑动视图大小,为yes时,自动从statuBar、navigationBar下面显示
self.automaticallyAdjustsScrollViewInsets = NO;
self.title = @"图片浏览";
//创建滑动视图
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
scrollView.delegate = self;
for (int i = 0; i < 5; i ++) {
PhotoScrollView *photoScrollView = [[PhotoScrollView alloc]initWithFrame:CGRectMake(scrollView.bounds.size.width * i, 0, scrollView.bounds.size.width, scrollView.bounds.size.height)];
photoScrollView.tag = i + 100;
//传值
photoScrollView.img = [UIImage imageNamed:[NSString stringWithFormat:@"%d.JPG", i]];
[scrollView addSubview:photoScrollView];
}
//取消滑动条的显示
scrollView.showsHorizontalScrollIndicator = NO;
//设置分页
scrollView.pagingEnabled = YES;
//设置内容尺寸
scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width * 5,scrollView.bounds.size.height);
[self.view addSubview:scrollView];
}
#pragma mark -UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//获取当前下标
NSInteger nowIndex = scrollView.contentOffset.x / scrollView.bounds.size.width;
if (nowIndex != _lastIndex) {
PhotoScrollView *photoScrollView = (PhotoScrollView *)[scrollView viewWithTag:_lastIndex + 100];
//还原
photoScrollView.zoomScale = 1;
}
_lastIndex = nowIndex;
}
}
@end
2、在滑动视图类中
@implementation PhotoScrollView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_imgView = [[UIImageView alloc]initWithFrame:self.bounds];
[self addSubview:_imgView];
//设置缩放的最大倍数
self.maximumZoomScale = 3;
self.minimumZoomScale = 1;
//取消滚动条
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
//设置代理
self.delegate = self;
//创建单击手势
UITapGestureRecognizer *navTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(navTapAction:)];
[self addGestureRecognizer:navTap];
//创建双击手势
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
doubleTap.numberOfTapsRequired = 2;
[self addGestureRecognizer:doubleTap];
[navTap requireGestureRecognizerToFail:doubleTap];
}
return self;
}
- (void)setImg:(UIImage *)img
{
if (_img != img) {
_img = img;
_imgView.image = self.img;
}
}
- (void)navTapAction:(UITapGestureRecognizer *)tap
{
//隐藏、显示导航栏
BOOL show = !self.viewController.navigationController.navigationBarHidden;
[self.viewController.navigationController setNavigationBarHidden:show animated:YES];
//隐藏、显示电池条
[[UIApplication sharedApplication] setStatusBarHidden:show withAnimation:UIStatusBarAnimationFade];
}
- (void)tapAction:(UITapGestureRecognizer *)tap
{
if (self.zoomScale > 1) {
//缩小
[self setZoomScale:1 animated:YES];
}else{
//放大
[self setZoomScale:3 animated:YES];
}
}
#pragma mark -UIScrollViewDelegate
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
9b13
return _imgView;
}
@end
3、通过响应者链找根视图控制器,创建uiview的类目,在里面写以下方法
-(UIViewController *)viewController
{
UIResponder *next = self.nextResponder;
do {
if ([next isKindOfClass:[UIViewController class]]) {
return (UIViewController *)next;
}
next = next.nextResponder;
} while (next);
return nil;
}
自习一天,复习UI前面的课程
8月14日
单元格的复用、单元格的常用属性、辅助图标、自适应高度
8月15日
单元格的定制的三种方法
8月16日
做课后作业,自习
8月17日
触摸与手势
8月18日
UIScrollView
综合性的示例:模拟相册
重要代码:
1、在根视图控制中:
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//设置视图控制器的滑动视图大小,为yes时,自动从statuBar、navigationBar下面显示
self.automaticallyAdjustsScrollViewInsets = NO;
self.title = @"图片浏览";
//创建滑动视图
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
scrollView.delegate = self;
for (int i = 0; i < 5; i ++) {
PhotoScrollView *photoScrollView = [[PhotoScrollView alloc]initWithFrame:CGRectMake(scrollView.bounds.size.width * i, 0, scrollView.bounds.size.width, scrollView.bounds.size.height)];
photoScrollView.tag = i + 100;
//传值
photoScrollView.img = [UIImage imageNamed:[NSString stringWithFormat:@"%d.JPG", i]];
[scrollView addSubview:photoScrollView];
}
//取消滑动条的显示
scrollView.showsHorizontalScrollIndicator = NO;
//设置分页
scrollView.pagingEnabled = YES;
//设置内容尺寸
scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width * 5,scrollView.bounds.size.height);
[self.view addSubview:scrollView];
}
#pragma mark -UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//获取当前下标
NSInteger nowIndex = scrollView.contentOffset.x / scrollView.bounds.size.width;
if (nowIndex != _lastIndex) {
PhotoScrollView *photoScrollView = (PhotoScrollView *)[scrollView viewWithTag:_lastIndex + 100];
//还原
photoScrollView.zoomScale = 1;
}
_lastIndex = nowIndex;
}
}
@end
2、在滑动视图类中
@implementation PhotoScrollView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_imgView = [[UIImageView alloc]initWithFrame:self.bounds];
[self addSubview:_imgView];
//设置缩放的最大倍数
self.maximumZoomScale = 3;
self.minimumZoomScale = 1;
//取消滚动条
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
//设置代理
self.delegate = self;
//创建单击手势
UITapGestureRecognizer *navTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(navTapAction:)];
[self addGestureRecognizer:navTap];
//创建双击手势
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
doubleTap.numberOfTapsRequired = 2;
[self addGestureRecognizer:doubleTap];
[navTap requireGestureRecognizerToFail:doubleTap];
}
return self;
}
- (void)setImg:(UIImage *)img
{
if (_img != img) {
_img = img;
_imgView.image = self.img;
}
}
- (void)navTapAction:(UITapGestureRecognizer *)tap
{
//隐藏、显示导航栏
BOOL show = !self.viewController.navigationController.navigationBarHidden;
[self.viewController.navigationController setNavigationBarHidden:show animated:YES];
//隐藏、显示电池条
[[UIApplication sharedApplication] setStatusBarHidden:show withAnimation:UIStatusBarAnimationFade];
}
- (void)tapAction:(UITapGestureRecognizer *)tap
{
if (self.zoomScale > 1) {
//缩小
[self setZoomScale:1 animated:YES];
}else{
//放大
[self setZoomScale:3 animated:YES];
}
}
#pragma mark -UIScrollViewDelegate
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
9b13
return _imgView;
}
@end
3、通过响应者链找根视图控制器,创建uiview的类目,在里面写以下方法
-(UIViewController *)viewController
{
UIResponder *next = self.nextResponder;
do {
if ([next isKindOfClass:[UIViewController class]]) {
return (UIViewController *)next;
}
next = next.nextResponder;
} while (next);
return nil;
}
相关文章推荐
- iOS开发笔记--iphone练习之手势识别(双击、捏、旋转、拖动、划动、长按)UITapGestureRecognize
- poj 1679 The Unique MST 【次小生成树+100的小数据量】
- iOS多线程-03-NSOperation与NSOperationQueue
- 发现UITableView留白问题解决办法
- IOS UI初级-滑动视图ScrollerView
- IOS UI初级-触摸与手势的基本概念和用法
- Win10 Build 10525系统详情页面出现Win8 Logo 已修复
- Unique Binary Search Trees II
- Codeforces 570D Tree Requests(DFS重标号+树状数组)
- DB Query Analyzer 6.04 is distributed, 78 articles concerned have been published
- uestc 94(区间更新)
- Max Sequence
- hdu(5400)——Arithmetic Sequence(想法题)
- 关情纸尾-----UIkit基础-UIScrollView
- 关于UITabBarController (非自定义)
- UIView 方法列表
- uva 10405 Longest Common Subsequence
- UIautomator输入中文
- Android自动化测试(UiAutomator)简要介绍
- 百度ueditor编辑器代码高亮