0

我有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一样缩放它作为图像而不是控件。

4

2 回答 2

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]];
于 2013-02-13T13:31:20.233 回答
0

如果你在 UIScrollView 中添加一个 UIScrollView 并使用委托方法,你可以做到这一点:

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

并且仅将 mainScroll 连接到委托,然后在 innerScroll 中添加您的子视图

于 2013-02-13T14:03:25.187 回答