UIViewAnimation阻止UIView交互

时间:2011-08-03 12:44:32

标签: iphone objective-c ios uiview uiviewanimation

我有一个名为MainViewController的UIViewController。 这是框架: 我还有一个名为SingleSearchView的UIView,它是MainViewController的子视图。

我将此singleSearchView添加到MainViewController:

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

当我尝试将以下动画“切换”到singleSearchView时,它会阻止我与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];

我也尝试过这种方式:

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

由于

3 个答案:

答案 0 :(得分:3)

从此answer to another question

  

默认情况下,UIView的块动画会阻止用户交互,要绕过它,您需要将UIViewAnimationOptionAllowUserInteraction作为其中一个选项传递。希望其他人也可以使用这些信息。

答案 1 :(得分:0)

你不应该试图移动self.view。 self.view属性在UIVIewControll层次结构中是特殊的。您应该创建一个子视图并为其设置动画...

答案 2 :(得分:0)

想出来!

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"];