0

我有一个 UIViewController 名为MainViewController. 它是框架:我还有一个名为 UIView 的 UIView SingleSearchView,它是 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];

谢谢

4

3 回答 3

3

从这个答案到另一个问题

原来 UIView 的块动画默认会阻止用户交互,要绕过它,您需要将 UIViewAnimationOptionAllowUserInteraction 作为选项之一传递。希望其他人也能使用这些信息。

于 2011-08-03T12:49:00.627 回答
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"];
于 2011-08-03T13:43:13.313 回答
0

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

于 2011-08-03T12:54:44.353 回答