简体   繁体   中英

UIView subview clips during UIView transition animation

I have created a UIView subclass which contains a UIImageView subview. The UIIMageView subview may typically lie outside the bounds of its superview (my UIView subclass). This is not a problem, no clipping occurs as my subview does not '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. During the transition bodyView clips. I have tried setting the 'masksToBounds' property of the superview's layer to 'NO' but this has not solved the problem.

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. 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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