开发者

UIViewAnimation block UIView interaction

I have an UIViewController named MainViewController. It's frame: I also have an UIView named SingleSearchView which is a subview of MainViewController.

And I add this singleSearchView to the MainViewController:

self.singleSearchView = [[SearchView alloc] initWithFrame:CGRectMake(0, -480, 320, 480)];
[self.view addSubview:singleSearchView];

When I'm trying the following animation to "switch" to the singleSearchView it blocks me from any touch interaction with the singleSearchView

[UIView beginAnimations:@"searchAnimation" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0f]; 
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.singleSearchView cache:YES];
[self.view setFrame:CGRectMake(0, 480, 320, 480)];    
[UIView commitAnimations];

I also tried this way:

[UIView animateWithDuration:1.5 delay:0 
                 options:UIViewAnimationOptionAllowUserInteraction 
                     animations:^{
                         [self.view setFrame:CGRectMake(0, 480, 320, 480)];  
                     }
                     completion:nil];

开发者_JAVA百科Thanks


From this answer to another question:

Turns out UIView's block animation by default blocks user interaction, and to get around it you need to pass UIViewAnimationOptionAllowUserInteraction as one of the options. Hopefully someone else will have some use of this information as well.


You shouldn't try to move self.view. The self.view property is special in the UIVIewControll hierarchy. You should create a subview and animate this one instead...


Figured it out!

CATransition* trans = [CATransition animation];
[trans setType:kCATransitionPush];
[trans setDuration:0.5];
[trans setSubtype:kCATransitionFromBottom];

[self.singleSearchView setFrame:CGRectMake(0, 0, 320, 480)];

CALayer *layer = self.view.layer;
[layer addAnimation:trans forKey:@"Transition"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜