[英]iOS 7 zooming is not working in ScrollView with AutoLayout but working in iOS8/9
I have made a demo for zoom image using UIScrollView
. 我使用
UIScrollView
制作了缩放图像演示。 My ViewController
only contains one image. 我的
ViewController
只包含一个图像。 The problem is the image cannot zoom in iO7
(I have tested on iPhone4S-iOS7
) but work perfectly in iOS8
/ iOS9
. 问题是图像无法放大
iO7
(我在iPhone4S-iOS7
上测试过)但在iOS8
/ iOS9
完美iOS9
。
Any ideas on how to fix it? 关于如何修复它的任何想法?
Here is my code 这是我的代码
#import "ViewController.h"
@interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
@property (weak, nonatomic) IBOutlet UIView *contentview;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
float minimumScale = [_contentview frame].size.width /[_scrollview frame].size.width;
_scrollview.maximumZoomScale = 5; //Change as per you need
_scrollview.minimumZoomScale = minimumScale; //Change as you need
_scrollview.zoomScale = minimumScale;
_scrollview.delegate =self;
_scrollview.clipsToBounds = YES;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return self.contentview;
}
@end
Here is the layout structure 这是布局结构
Screen.png constraint Screen.png约束
ContentView constraint
ContentView约束
ScrollView constraint ScrollView约束
Here is my demo project 这是我的演示项目
https://drive.google.com/file/d/0B679aXO0SBmMeUVHTUdOcmxJSXM/view https://drive.google.com/file/d/0B679aXO0SBmMeUVHTUdOcmxJSXM/view
The height and width constraints
are causing this in iOS 7. A workaround would be, removing those constraints
for iOS 7 and calculate minimumScale
manually. 高度和宽度
constraints
在iOS 7中引起这种情况。解决方法是,删除iOS 7的constraints
并手动计算minimumScale
。 in IOS 8 and above, do not change anything. 在IOS 8及以上版本中,不要更改任何内容。
- (void)viewDidLoad {
[super viewDidLoad];
float minimumScale = 1;
if (floor(NSFoundationVersionNumber) < NSFoundationVersionNumber_iOS_8_0) {
[self.view removeConstraints:self.heightWidthConstraints];
minimumScale = self.scrollview.frame.size.width / self.imageView.image.size.width;
}
_scrollview.maximumZoomScale = 5; //Change as per you need
_scrollview.minimumZoomScale = minimumScale; //Change as you need
//_scrollview.zoomScale = minimumScale;
_scrollview.delegate = self;
//_scrollview.clipsToBounds = YES;
[self.scrollview setZoomScale:minimumScale animated:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.