简体   繁体   中英

Animated UIView hangs on screen after pressing back

I can't figure out what's happening here. I have two views on screen that serve as a "gate" until the camera is ready to record. Afterwards they slide out. It works, i'm happy, and that's great. The problem is regardless of when I choose to go "back" on the navigation controllers back option (be that during the animation or after it finishes) the left view "sticks out" on the view controller i'm going back to.

I've tried removing all animations -and- removing the views from the superview when the ViewWillDisappear method... but no luck, this view persistently sticks out on the home page when I click back from the recording page.

-(void)animateViewsOut
{
[UIView animateKeyframesWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionCurveEaseIn animations:^{
    _leftView.layer.transform = CATransform3DMakeTranslation(-_leftView.frame.size.width, 0.0, 0.0);
    _rightView.layer.transform = CATransform3DMakeTranslation(_rightView.frame.size.width, 0.0, 0.0);
} completion:^(BOOL finished) {
    [_leftView removeFromSuperview];
    [_rightView removeFromSuperview];
}];
}

and my attempt to solve the problem

- (void) viewWillDisappear:(BOOL)animated
{

[super viewWillDisappear:animated];
[_leftView.layer removeAllAnimations];
[_rightView.layer removeAllAnimations];
[_leftView removeFromSuperview];
[_rightView removeFromSuperview];
[[CameraEngine engine] shutdown];

}

So, as it turns out the problem's root was due to me inserting the views on the view controllers main view

[self.view addsubview:_leftView];
[self.view addsubview:_rightView];

I instead created a container for the views that I built onto the storyboard, then added the the views as subviews of that overview, and kept the same animation, except on completion instead of removing the views individually, I just remove the overlay container instead (change in the code below).

-(void)animateViewsOut
{
[UIView animateKeyframesWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut |     UIViewAnimationOptionCurveEaseIn animations:^{
_leftView.layer.transform = CATransform3DMakeTranslation(-_leftView.frame.size.width, 0.0, 0.0);
_rightView.layer.transform = CATransform3DMakeTranslation(_rightView.frame.size.width, 0.0, 0.0);
} completion:^(BOOL finished) {
[_overlayView removeFromSuperview];
}];
}

After I made this change, the views didn't persist when tapping back in the navigation controller.

I removed all of the code from the viewWillDisappear method, removing the overlay container after the animation completed solved the problem on its own.

- (void) viewWillDisappear:(BOOL)animated {}

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