【发布时间】:2014-04-07 17:41:58
【问题描述】:
今天,我试图让视图在取消后返回到其默认原点。我正在使用两个 VC 来做到这一点。一个是tableview中的footer controller,另一个是modal view,在第一个动画之后呈现。每当我尝试从模态视图返回时,在我完成第一个动画之后,原点仍然是相同的。这是我正在使用的代码:
Footer:
-(IBAction)addPerson:(id)sender{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
NSLog(@"%f", self.view.frame.origin.y);
self.view.frame = CGRectMake(0,-368,320,400);
[UIView commitAnimations];
self.tdModal2 = [[TDSemiModalViewController2 alloc]init];
// [self.view addSubview:test.view];
[self presentSemiModalViewController2:self.tdModal2];
}
-(void)moveBack{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
NSLog(@"%f", self.view.frame.origin.y);
self.view.frame = CGRectMake(0,368,320,400);
[UIView commitAnimations];
}
在模态视图中:
-(IBAction)cancel:(id)sender{
[self dismissSemiModalViewController:self];
FooterViewController *foot = [[FooterViewController alloc]init];
self.footer = foot;
// self.footer.view.frame = CGRectMake(0,35,320,400);
[self.footer moveBack];
}
【问题讨论】:
-
我认为您的代码是错误的,您在取消方法中创建了一个新的 FooterViewController,但您没有为其分配任何视图;或者如果它是自动分配的,那么它当然会从原点创建,就好像它是一个新的一样;它与您之前动画的 footer.view 不同。
-
另外,在 iOS 4.0 及更高版本中不鼓励使用 [UIView beginAnimations]。您应该使用基于块的动画方法来指定您的动画。
-
@htafoya 嗯。我见过的大多数例子都使用了它。另外,对于所述问题,您是否有“可靠”的解决方案?
-
让我试着理解一下,您单击一个隐藏(或移动)页脚的按钮并打开一个模式。在模式上单击取消后,页脚应返回其原始位置。这是正确的,我会发布我推荐的答案。
标签: ios iphone objective-c uiview ibaction