使 UIView 可缩放

发布于 2024-10-08 20:11:58 字数 1694 浏览 4 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高速公鹿 2024-10-15 20:11:58

您是否实现了 scrollViewDidEndZooming:withView:atScale: ?我还注意到您注释掉了初始化 minimumZoomScalemaximumZoomScale 的代码。最好正确设置。

来自 UIScrollView 类参考

为了进行缩放和平移,
委托必须同时实现
viewForZoomingInScrollView:
scrollViewDidEndZooming:withView:atScale:;
此外,最大
(最大缩放比例)和最小(
minimumZoomScale)缩放比例必须不同

Did you implement scrollViewDidEndZooming:withView:atScale:? I also noticed that you commented out the code initializing minimumZoomScale and maximumZoomScale. Better to set that correctly.

From the UIScrollView Class Reference:

For zooming and panning to work, the
delegate must implement both
viewForZoomingInScrollView: and
scrollViewDidEndZooming:withView:atScale:;
in addition, the maximum
(maximumZoomScale) and minimum (
minimumZoomScale) zoom scale must be different.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文