使 UIView 可缩放
我正在 iPhone 上使用 UIScrollView,并且我希望能够缩放 UIView。
我的 UIView 是 ma uiscrollview 的子视图。如果我返回视图,当我尝试缩放时,我的视图会移动但不会缩放:
- (void)viewDidLoad {
[super viewDidLoad];
//mon label peut prendre la valeur de mon menu
[monLabel setText:monMenu];
CGRect frame = CGRectMake(1, 1, 320, 480); // Replacing with your dimensions
maVue = [[UIView alloc] initWithFrame:frame];
maVue.userInteractionEnabled = YES;
scrollView.contentSize = CGSizeMake(320, 480);
scrollView.bounces = YES;
//scrollView.bouncesZoom = YES;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.scrollEnabled = YES;
//scrollView.minimumZoomScale = 1.0;
//scrollView.maximumZoomScale = 5.0;
scrollView.delegate = self;
[scrollView addSubview:maVue];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView
*)scrollView{ return maVue; }
例如,如果我用标签替换我的视图:
- (void)viewDidLoad {
[super viewDidLoad];
//mon label peut prendre la valeur de mon menu
[monLabel setText:monMenu];
CGRect frame = CGRectMake(1, 1, 320, 480); // Replacing with your dimensions
maVue = [[UIView alloc] initWithFrame:frame];
maVue.userInteractionEnabled = YES;
scrollView.contentSize = CGSizeMake(320, 480);
scrollView.bounces = YES;
//scrollView.bouncesZoom = YES;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.scrollEnabled = YES;
//scrollView.minimumZoomScale = 1.0;
//scrollView.maximumZoomScale = 5.0;
scrollView.delegate = self;
[scrollView addSubview:monLabel];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView
*)scrollView{ return monLabel; }
缩放效果很好。我的标签被放大了。
你知道为什么它适用于标签但不适用于 UIView 吗?
谢谢
你吗
I am using the UIScrollView on iphone, and I want to be able to zoom on an UIView.
my UIView is a subview of ma uiscrollview. If I return the view, when I tried to zoom, my view move but dont zoom :
- (void)viewDidLoad {
[super viewDidLoad];
//mon label peut prendre la valeur de mon menu
[monLabel setText:monMenu];
CGRect frame = CGRectMake(1, 1, 320, 480); // Replacing with your dimensions
maVue = [[UIView alloc] initWithFrame:frame];
maVue.userInteractionEnabled = YES;
scrollView.contentSize = CGSizeMake(320, 480);
scrollView.bounces = YES;
//scrollView.bouncesZoom = YES;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.scrollEnabled = YES;
//scrollView.minimumZoomScale = 1.0;
//scrollView.maximumZoomScale = 5.0;
scrollView.delegate = self;
[scrollView addSubview:maVue];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView
*)scrollView{ return maVue; }
if I replace my view by a label for exemple :
- (void)viewDidLoad {
[super viewDidLoad];
//mon label peut prendre la valeur de mon menu
[monLabel setText:monMenu];
CGRect frame = CGRectMake(1, 1, 320, 480); // Replacing with your dimensions
maVue = [[UIView alloc] initWithFrame:frame];
maVue.userInteractionEnabled = YES;
scrollView.contentSize = CGSizeMake(320, 480);
scrollView.bounces = YES;
//scrollView.bouncesZoom = YES;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.scrollEnabled = YES;
//scrollView.minimumZoomScale = 1.0;
//scrollView.maximumZoomScale = 5.0;
scrollView.delegate = self;
[scrollView addSubview:monLabel];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView
*)scrollView{ return monLabel; }
the zoom works well. My label magnified.
Do you have any idea why it's working for a label but not for an UIView?
thanks
Do you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否实现了
scrollViewDidEndZooming:withView:atScale:
?我还注意到您注释掉了初始化minimumZoomScale
和maximumZoomScale
的代码。最好正确设置。来自 UIScrollView 类参考:
Did you implement
scrollViewDidEndZooming:withView:atScale:
? I also noticed that you commented out the code initializingminimumZoomScale
andmaximumZoomScale
. Better to set that correctly.From the UIScrollView Class Reference: