iOS使用UIScrollerView进行图片缩放,实现仿新闻图片阅读功能
来源:互联网 发布:淘宝买管制刀具 编辑:程序博客网 时间:2024/05/01 18:02
这是一个简单的仿一些新闻客户端图片查看功能,但是这个完成的比较简单只能点击查看一张照片,使用UIScrollerView实现了一个图片缩放的功能。
#import "ViewController.h"@interface ViewController ()@property (nonatomic, strong) UIImageView *imageView;@property (nonatomic, strong) UIScrollView *scrollView;@property (nonatomic, strong) UIButton *delBtn;@property (nonatomic, strong) UILabel *textLabel;@property (nonatomic, strong) UITapGestureRecognizer *recognizer;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. //初始化UIScrollerView占满整个屏幕 self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.view addSubview:self.scrollView]; //初始化一张图片,居中显示 UIImage *image = [UIImage imageNamed:@"222.jpg"]; self.imageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.imageView.image = image; self.imageView.contentMode = UIViewContentModeCenter; [self.scrollView addSubview:self.imageView]; //设置代理,并设置最大和最小缩放比例 self.scrollView.delegate = self; self.scrollView.maximumZoomScale = 2; self.scrollView.minimumZoomScale = 1.0; //初始化一个按钮 self.delBtn = [UIButton buttonWithType:UIButtonTypeContactAdd]; [self.delBtn setFrame:CGRectMake(10, 20, 30, 30)]; [self.view addSubview:self.delBtn]; [self.delBtn setBackgroundColor:[UIColor clearColor]]; //初始化一个label self.textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 620, 350, 20)]; self.textLabel.text = @"This is just a test, Can be more complex"; self.textLabel.backgroundColor = [UIColor clearColor]; self.textLabel.textColor = [UIColor whiteColor]; [self.view addSubview:self.textLabel]; //初始化手势操作,并为UIView添加手势控制 self.recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView:)]; [self.view addGestureRecognizer:self.recognizer]; self.recognizer.numberOfTapsRequired = 1; self.recognizer.numberOfTouchesRequired = 1; [self.view setBackgroundColor:[UIColor blackColor]];}//代理需要实现的函数,返回要被缩放的UIView控件,即为UIImageView- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imageView;}//点击屏幕后的操作- (void)tapView:(UITapGestureRecognizer*)gesture { if (self.delBtn.hidden) [self showSubView]; else [self hideSubView];}//以动画的方式使按钮消失- (void)hideSubView { CATransition *animation = [CATransition animation]; animation.type = kCATransitionFade; animation.duration = 0.3; [self.delBtn.layer addAnimation:animation forKey:nil]; [self.textLabel.layer addAnimation:animation forKey:nil]; self.delBtn.hidden = YES; self.textLabel.hidden = YES;}//以动画的方式显示按钮- (void)showSubView { CATransition *animation = [CATransition animation]; animation.type = kCATransitionReveal; animation.duration = 0.3; [self.delBtn.layer addAnimation:animation forKey:nil]; [self.textLabel.layer addAnimation:animation forKey:nil]; self.delBtn.hidden = NO; self.textLabel.hidden = NO;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
此时不能进行滑动,这符合我们得要求,点击屏幕后会发现左上角的按钮和下方的标签都渐近消失了。
单击并进行缩放之后的效果,可以上下左右移动查看未显示的图片,在此处并没有很好的实现,垂直滑动会有很大一片空白。
0 0
- iOS使用UIScrollerView进行图片缩放,实现仿新闻图片阅读功能
- Android使用PhotoView实现图片缩放功能
- Android使用PhotoView实现图片缩放功能
- iOS 使用UIScrollView实现图片的缩放
- JS实现图片缩放功能
- 图片的缩放功能实现
- 使用Thumbnails进行图片缩放
- 图片实现缩放功能,设置缩放比例
- iOS——使用ScrollView进行图片的缩放
- 仿新闻图片浏览
- 使用Photoview实现图片左右滑动及缩放功能
- IOS 对UIImage图片进行缩放
- iOS 利用UIScrollView 对图片进行缩放
- 如何实现Imageview图片进行缩放
- Android实现图片的缩放翻转功能
- Android实现图片的缩放翻转功能
- android开发-图片缩放,拖动功能实现。
- JAVA实现图片剪切缩放功能
- android intent 用法
- C++的errorC2039和C2679的解决
- 代理中触发表单按钮
- JQuery选择器大全
- SpringMVC jpa 分页问题
- iOS使用UIScrollerView进行图片缩放,实现仿新闻图片阅读功能
- zookeeper四字命令
- 一些应该知道的语言
- 数据结构笔记之线性存储
- Java内存与垃圾回收调优
- LabView 队列的使用,以及VI之间的传值
- 只会左键断点?是时候试试这样那样断点了
- CObList
- 散列表的C语言实现-分离链接法