简体   繁体   English

使用 UIScrollView 子视图调整 UIView 的大小

[英]Resizing UIView with UIScrollView subview

I have a big problem concerning the resizing of a derived UIView with a UIScrollView as subview.我有一个关于使用UIScrollView作为子视图调整派生UIView大小的大问题。

In the layoutSubviews message I set the frame of the UIScrollView subview.layoutSubviews消息中,我设置了 UIScrollView 子视图的框架。 the UIScrollView contains a UIImageView with a big image which can be moved/pinched and so on. UIScrollView包含一个带有大图像的UIImageView ,可以移动/捏合等等。 The initial contenSize of the UIScrollView is the initial image size. UIScrollView的初始contenSize是初始图像大小。

So far, so good.到现在为止还挺好。 Moving and pinching of the image works well.图像的移动和捏合效果很好。 Now I have to change the UIView frame (in my app to maximize the UIView).现在我必须更改 UIView 框架(在我的应用程序中最大化 UIView)。 im doing that in a animation block ( beginAnimations / commitAnimations ).我在动画块( beginAnimations / commitAnimations )中这样做。 So I set the new frame (which will update the width & height) an then I call [myView layoutIfNeeded] to force the UIScrollView to update its frame in the layoutSubviews message of my view.因此,我设置了新框架(将更新宽度和高度),然后调用[myView layoutIfNeeded]强制 UIScrollView 在我的视图的layoutSubviews消息中更新其框架。

The UIView animates correct to its new frame and if the contentOffset of the UIScrollView is currently x 0, y 0 the UIScrollView frame will be updated properly. UIView对其新框架进行动画处理,如果UIScrollViewcontentOffset当前为x 0, y 0UIScrollView框架将正确更新。 but here's my problem: if the contentOffset of the UIScrollView is bigger than x 0, y 0 the UIScrollView will "slide in" from upper left to its final position.但这是我的问题:如果UIScrollViewcontentOffset大于x 0, y 0 UIScrollView将从左上角“滑入”到其最终位置。

I want that the UIScrollView resizes its frame properly with the parents frame and aligns the content (in my case the UIImageView ) right.我希望 UIScrollView 使用父框架正确调整其框架的大小,并将内容(在我的情况下为UIImageView )对齐。 But how could I achieve that?但我怎么能做到这一点呢?

after hours of web research i found the solution for this problem:经过数小时的网络研究,我找到了解决此问题的方法:

[UIView setAnimationBeginsFromCurrentState: YES];

this will animate all layers from the current state.这将从当前状态为所有图层设置动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM