缩放UIScrollView(不仅仅是其内容)

时间:2013-02-13 13:07:43

标签: iphone ios objective-c uiscrollview uikit

UIScrollview有几个UIViews初始化。

如果我缩放它并不会真正扩展我的scrollview,但它会以非常奇怪的方式缩放scrollview中的内容,

 _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 60.0f, self.bounds.size.width, self.bounds.size.height-60.0f)];
 [self addSubview:_scrollView];
 [_scrollView.layer setAffineTransform:CGAffineTransformScale(_scrollView.layer.affineTransform, .5, .5)];

是否可能在整体中扩展scrollview而不仅仅是内容。 我想像我的UIScrollView一样将其缩放为图像,而不是控件。

2 个答案:

答案 0 :(得分:1)

你可以试试这个:

- (CGRect)zoomRectForScale:(float)scale withScrollView:(UIScrollView *)yourScrollView {

    CGRect zoomRect;

    zoomRect.size.height = [yourScrollView frame].size.height / scale;
    zoomRect.size.width  = [yourScrollView frame].size.width / scale;


    zoomRect.origin.x = (yourScrollView.theScrollView.x - zoomRect.size.width  / 2.0);
    zoomRect.origin.y = (yourScrollView.center.y - zoomRect.size.height / 2.0);

    return zoomRect;

    }

    ...

    [yourScrollView setFrame:[self zoomRectForScale:5 withScrollView:yourScrollView]];

答案 1 :(得分:0)

如果在UIScrollView中添加UIScrollView,则可以执行此操作 并使用委托方法:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return innerScroll;
}

并且只将mainScroll连接到委托 然后在innerScroll

中添加您的子视图