我使用UIScrollView
制作了缩放图像演示。我的ViewController
只包含一张图片。
问题是图片无法放大iO7
(我已在iPhone4S-iOS7
上测试过)但在iOS8
/ iOS9
中完美运行。
关于如何解决它的任何想法?
这是我的代码
#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
这是布局结构
Screen.png 约束
ContentView 约束
ScrollView 约束
这是我的演示项目
https://drive.google.com/file/d/0B679aXO0SBmMeUVHTUdOcmxJSXM/view
答案 0 :(得分:1)
高度和宽度constraints
在iOS 7中导致此问题。解决方法是,删除iOS 7的constraints
并手动计算minimumScale
。在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];
}
答案 1 :(得分:0)