[英]View not animating
我正在使用此方法尝试将视图向上移动,但是没有成功,这是MainViewController实现文件中的代码:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGRect rect = self.view.frame;
if (movedUp)
{
NSLog(@"should move Up");
rect.origin.y -= 50;
rect.size.height += 300;
}
self.view.frame = rect ;
[UIView commitAnimations];
它没有出错,它正在打印“应该向上移动”,因此我知道该方法已正确执行。
这是IB层次结构(我正在尝试移动突出显示的视图):
任何帮助将不胜感激,我用尽了想法..
好的,在这里进行编辑,我将问题隔离为其他问题,现在正在使用以下代码:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
self.containerView.frame = CGRectMake(0, 0, 250, 50);
[UIView commitAnimations];
如果我将此代码注入“-(void)viewDidLoad”中,它将正常工作。
但是如果我在同一ViewController实现文件中的不同函数中使用相同的代码,则无法正常工作:
- (void)setViewMovedUp:(BOOL)movedUp {
NSLog(@"test movedUp");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
self.containerView.frame = CGRectMake(0, 0, 250, 50);
[UIView commitAnimations];
}
但是它仍在打印“测试向上移动”,因此代码被执行,只是视图没有动画。
通过使用tableview作为水平滚动并对该视图进行动画处理并还对诸如选取框动画之类的文本进行动画处理 ,通过方法-(void)handleSwipeGesture:(UISwipeGestureRecognizer *)发送者
尝试移动另一种视图-不是主要视图。
可能在移动主视图时出现问题。
如果可行,则在您的视图层次结构中添加一个视图,该视图将包含所有其他视图,并将其连接到IBOutlet。
如果它不起作用,请评论我,我们将尝试找出答案...
采用
[self.view setFrame:rect];
代替
self.view.frame = rect ;
我认为该动画将不会用于self.view
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.