使UIView可缩放

时间:2010-12-22 20:30:10

标签: objective-c xcode uiview uiscrollview zooming

我在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吗?

谢谢

1 个答案:

答案 0 :(得分:0)

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

来自UIScrollView Class Reference

  

要进行缩放和平移工作,请执行此操作   代表必须实施两者   viewForZoomingInScrollView:和   scrollViewDidEndZooming:withView:atScale:;   另外,最大   (maximumZoomScale)和最小值(   minimumZoomScale)缩放比例必须不同