【发布时间】:2015-01-29 10:42:30
【问题描述】:
我试图弄清楚这是否可能。我的UIViewController(与屏幕大小相同)中有一个UIScrollView,设置的内容大小为640*640。滚动视图中的UIView,大小为 640
*640。代码:
#import "ViewController.h"
@interface ViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) UIView *viewForZoom;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width / 2;
//self.profileImageView.clipsToBounds = YES;
UIView *content = [[[NSBundle mainBundle] loadNibNamed:@"floatingView" owner:self options:nil] objectAtIndex:0];
self.viewForZoom=content; //need this pointer for the zoom
self.scrollView.contentSize=CGSizeMake(640 ,640);
self.scrollView.minimumZoomScale=0.25;
self.scrollView.maximumZoomScale=1;
[self.scrollView addSubview:content];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return self.viewForZoom;
}
这会按预期进行缩放和平移:
当完全缩小时,视图会停留在屏幕的左上角。我想要发生的是,当视图缩小时,它会粘在屏幕的中心,但它也可以在 640*640 容器内拖动。这是可能的吗?任何帮助,将不胜感激。谢谢
【问题讨论】:
标签: ios xcode uiview uiscrollview