IOS开发UI阶段 第六周
来源:互联网 发布:白银现货交易软件 编辑:程序博客网 时间:2024/06/06 02:29
- (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
@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
{
return _imgView;
}
@end
-(UIViewController *)viewController
{
UIResponder *next = self.nextResponder;
do {
if ([next isKindOfClass:[UIViewController class]]) {
return (UIViewController *)next;
}
next = next.nextResponder;
} while (next);
return nil;
}
- IOS开发UI阶段 第六周
- IOS开发UI阶段 第五周
- iOS开发UI阶段 第七周
- ios开发 UI阶段第八周
- iOS开发之 UI 编程——第六讲
- iOS学习----UI阶段基础资料汇总
- ios学习开发阶段小结
- iOS-学习笔记-UI-第六天
- iOS: UI 开发
- iOS UI Tab开发
- iOS开发 ----- UI生命周期
- IOS-UI-基础开发
- iOS开发 UI--动画
- IOS开发 UI UISlider
- IOS开发UI-------label
- IOS开发UI-------button
- iOS开发UI篇
- iOS开发UI篇
- https://software.intel.com/zh-cn/blogs/2014/02/20/svn/
- PHP中 include, include_once, require, require_once的区别
- OpenCV中Adaboost训练的经验总结
- jQuery使用手册
- 单例模式的优点-缺点
- IOS开发UI阶段 第六周
- PHP实现一致性散列算法
- IT 毕业生薪资
- UVA673 Parentheses Balance
- JsonUtils & json转换
- IOS contentSize contentInset contengOffset 的区别的理解
- C++类继承关系问题
- 重写对象toString方法
- 过去的数据如何帮助团队改进