[iOS]图组全屏可缩放和旋转屏幕来展示
来源:互联网 发布:手机声音美化软件 编辑:程序博客网 时间:2024/06/02 08:18
[iOS]图组全屏可缩放和旋转屏幕来展示
Demo:http://download.csdn.net/detail/u012881779/9775105
因为要加载图片,所以先导入了工具SDWebImage;
#import "GraphicDetailsViewController.h"#import "UIImageView+WebCache.h"@interface GraphicDetailsViewController () <UIScrollViewDelegate>@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;@property (strong, nonatomic) NSArray *picArr;@property (assign,nonatomic) NSInteger pageIndex;@end@implementation GraphicDetailsViewController@synthesize dataMDict = _dataMDict;- (void)dealloc { _dataMDict = nil; self.picArr = nil;}- (void)viewDidLoad { [super viewDidLoad]; self.pageIndex = [[_dataMDict objectForKey:@"index"] integerValue]; self.picArr = [_dataMDict objectForKey:@"array"]; [self settingAction:YES]; [self creatPictureAction]; // 设备旋转通知 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDeviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];}- (BOOL)prefersStatusBarHidden { return YES ;}- (void)settingAction:(BOOL)result { self.title = @"图片详情"; [self.navigationController setNavigationBarHidden:result]; // iOS7之后 if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)]; } // iOS9之后 [[UIApplication sharedApplication] setStatusBarHidden:result];}- (IBAction)tapBackViewAction:(id)sender { [self settingAction:NO]; [self.navigationController popViewControllerAnimated:NO]; [self.navigationController setNavigationBarHidden:NO]; [[UIApplication sharedApplication] setStatusBarHidden:NO];}- (void)creatPictureAction { for (int i = 0; i < self.picArr.count ; i ++) { NSString *imgUrl = [self.picArr objectAtIndex:i]; UIScrollView *backScrollView = [[UIScrollView alloc] init]; backScrollView.backgroundColor = [UIColor clearColor]; [backScrollView setShowsVerticalScrollIndicator:NO]; [backScrollView setShowsHorizontalScrollIndicator:NO]; [backScrollView.layer setMasksToBounds:YES]; backScrollView.delegate = self; backScrollView.maximumZoomScale = 3.0; backScrollView.minimumZoomScale = 1.0; [_scrollView addSubview:backScrollView]; UIImageView *tempIV = [[UIImageView alloc] init]; [tempIV sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"qspic.png"]]; [tempIV setContentMode:UIViewContentModeScaleAspectFit]; [backScrollView addSubview:tempIV]; } [self adaptiveImageViewFrame];}#pragma mark UIScrollViewDelegate- (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.tag == 2300) { CGPoint osPoint = scrollView.contentOffset; osPoint.y = 0; scrollView.contentOffset = osPoint; }}- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { if (scrollView.tag == 2300) { CGPoint osPoint = scrollView.contentOffset; NSInteger index = (osPoint.x + [UIScreen mainScreen].bounds.size.width/2.0) / [UIScreen mainScreen].bounds.size.width; osPoint.x = [UIScreen mainScreen].bounds.size.width * index; [UIView animateWithDuration:0.2 animations:^{ scrollView.contentOffset = osPoint; } completion:nil]; self.pageIndex = index; }}// 通过ScrollView的这个代理方法来实现图片的缩放- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { if (scrollView.tag != 2300) { NSArray *subViews = [scrollView subviews]; UIImageView *imageView; for (int i = 0; i < subViews.count ; i ++) { UIView *tempView = [subViews objectAtIndex:i]; if ([[tempView class] isSubclassOfClass:[UIImageView class]]) { imageView = (UIImageView *)tempView; } } return imageView; } else { return nil; }}// 监控屏幕旋转- (void)handleDeviceOrientationDidChange:(UIInterfaceOrientation)interfaceOrientation{ UIDevice *device = [UIDevice currentDevice] ; switch (device.orientation) { case UIDeviceOrientationFaceUp: NSLog(@"屏幕朝上平躺"); break; case UIDeviceOrientationFaceDown: NSLog(@"屏幕朝下平躺"); break; case UIDeviceOrientationUnknown: NSLog(@"未知方向"); break; case UIDeviceOrientationLandscapeLeft: NSLog(@"home键在右"); break; case UIDeviceOrientationLandscapeRight: NSLog(@"home键在左"); break; case UIDeviceOrientationPortrait: NSLog(@"home键在下"); break; case UIDeviceOrientationPortraitUpsideDown: NSLog(@"home键在上"); break; default: NSLog(@"无法辨识"); break; } [self adaptiveImageViewFrame];}// 设置scrollView和imageView的frame- (void)adaptiveImageViewFrame { float sWith = [UIScreen mainScreen].bounds.size.width; float sHigh = [UIScreen mainScreen].bounds.size.height; NSMutableArray *subSVArr = [[NSMutableArray alloc] init]; NSArray *subArr = _scrollView.subviews; for (int i = 0; i < subArr.count ; i ++) { UIView *tempView = [subArr objectAtIndex:i]; if ([[tempView class] isSubclassOfClass:[UIScrollView class]]) { [subSVArr addObject:tempView]; } } for (int i = 0; i < subSVArr.count ; i ++) { UIScrollView *tempView = [subSVArr objectAtIndex:i]; [tempView setFrame:CGRectMake(sWith*i, 0, sWith, sHigh)]; [[[tempView subviews] firstObject] setFrame:tempView.bounds]; } [_scrollView setContentSize:CGSizeMake(sWith*subSVArr.count, sHigh)]; NSInteger index = self.pageIndex; CGPoint osPoint = _scrollView.contentOffset; osPoint.y = 0; osPoint.x = sWith * index; _scrollView.contentOffset = osPoint;}@end
示意图:
0 0
- [iOS]图组全屏可缩放和旋转屏幕来展示
- 【Unity】手势缩放屏幕和旋转视角
- Unity3d 手势缩放屏幕和旋转视角
- iOS 指定部分页面可屏幕旋转
- ios 关于屏幕旋转和屏幕晃动
- IOS&Android通用屏幕控制(移动旋转缩放)
- IOS&Android通用屏幕控制(移动旋转缩放)
- [IOS]图片的旋转和缩放
- iOS 手势识别 旋转和缩放(捏合)
- Android基础之去掉标题栏实现全屏和旋转屏幕
- UNITY手指接触屏幕对物体进行旋转和缩放
- 源码推荐(7.29):iOS图片查看器(多图全屏查看可缩放),给UITextView 添加超链接
- ios 图片缩放/旋转
- iOS 屏幕旋转 手动和自动
- iOS手动和自动旋转屏幕
- Android视频旋转并全屏展示
- krpano实践之全景图缩放,旋转,倾斜,自动旋转,VR,全屏方法
- krpano实践之全景图缩放,旋转,倾斜,自动旋转,VR,全屏方法-js调用
- solr6.3.0安装启动,以及core创建和导入数据
- ArrayBlockingQueue源码解析
- 为什么使用Spring框架
- Hive,Hbase,HDFS等之间的关系
- 让Phpcms 单页左栏只显示同级栏目的办法
- [iOS]图组全屏可缩放和旋转屏幕来展示
- Android反调试方法总结以及源码实现之检测篇(一)
- Linux之vi三种模式常用操作的学习
- XML映射配置
- jpa 的多对多的属性时查询的两种方式
- 导入新项目后 出现红叉 红叹号
- 几何画板如何生成三角函数图像
- iBET Live Casinos Rebate 0.75% Bonus
- Install Oracle 11G Release 2 (11.2) on Oracle Linux 7 (OEL7),备忘