[英]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
对其新框架进行动画处理,如果UIScrollView
的contentOffset
当前为x 0, y 0
则UIScrollView
框架将正确更新。 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.但这是我的问题:如果
UIScrollView
的contentOffset
大于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.