简体   繁体   English

UIView 过渡动画期间的 UIView 子视图剪辑

[英]UIView subview clips during UIView transition animation

I have created a UIView subclass which contains a UIImageView subview.我创建了一个 UIView 子类,其中包含一个 UIImageView 子视图。 The UIIMageView subview may typically lie outside the bounds of its superview (my UIView subclass). UIIMageView 子视图通常可能位于其超视图(我的 UIView 子类)的边界之外。 This is not a problem, no clipping occurs as my subview does not 'clipsToBounds'.这不是问题,因为我的子视图没有“clipsToBounds”,所以不会发生剪辑。 That is until my subview performs a transition animation.直到我的子视图执行过渡动画。

[UIView transitionWithView:self
                      duration:0.7
                       options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionAllowAnimatedContent
                    animations:^{
                        self.bodyView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
                    }
                    completion:^(BOOL fin){
                    }];

In this example 'bodyView' is the UIImageView subview of my UIView subclass.在这个例子中,'bodyView' 是我的 UIView 子类的 UIImageView 子视图。 During the transition bodyView clips.在过渡时 bodyView 剪辑。 I have tried setting the 'masksToBounds' property of the superview's layer to 'NO' but this has not solved the problem.我曾尝试将超级视图层的“masksToBounds”属性设置为“NO”,但这并没有解决问题。

My only workaround at present is for the superview to be much larger than the subview and not allow the subview's frame to exist outside the superview's bounds but this is not practical in my application.我目前唯一的解决方法是让父视图比子视图大得多,并且不允许子视图的框架存在于父视图的边界之外,但这在我的应用程序中不实用。

I've solved it.我已经解决了。 It was a problem of my own making I'm afraid.恐怕这是我自己造成的问题。 I referenced the wrong view in the transitionWithView:duration:options:animations: -method.我在transitionWithView:duration:options:animations: -method 中引用了错误的视图。 I should have referenced the view that was animating ie the subview.我应该引用动画的视图,即子视图。 Code now works without clipping like so:代码现在无需剪辑即可工作,如下所示:

[UIView transitionWithView:self.bodyView
                  duration:0.7
                   options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionAllowAnimatedContent
                animations:^{
                        self.bodyView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
                    }
                    completion:^(BOOL fin){
                    }];

尝试这个:

imgView.contentMode = UIViewContentModeScaleAspectFit;

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

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