我有一个简单的动画,可以反复上下移动幻灯片。以下是代码:
CGRect frm_down = slider.frame;
frm_down.origin.y += 50;
[UIView animateWithDuration:0.7
delay:0.0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations:^{
slider.frame = frm_down;
}
completion:NULL];
这是非常直截了当的,而且效果很好;但是,当我呈现视图(:动画:)时,动画不会发生。
实际上,滑块会立即移动到较低的位置(就好像它只调用了动画一次,并将其向下移动,而不是后退)。
我也尝试过这样做:
CGRect frm_down = [[[slider layer] presentationLayer] frame]
这将保持滑块在其原来的位置,而不是向下移动一次,动画仍然没有发生。
知道我错过了什么吗?谢谢!
发布于 2014-01-30 23:55:32
你的动画作品。我测试过了。
你需要的是:
而不是使用:
self presentViewController:animated:
用这个:
[self addChildViewController:<YOUR_VIEWCONTROLLER>];
[self.view addSubview:<YOUR_VIEWCONTROLER>.view];
[<YOUR_VIEWCONTROLER> didMoveToParentViewController:self];
增编:
在视图控制器的viewDidAppear
中,添加以下代码:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect frm_down = self.view.frame;
frm_down.origin.y += 50;
[UIView animateWithDuration:0.7
delay:0.0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations:^{
self.view.frame = frm_down;
}
completion:NULL];
}
当它出现在视野中时,它就会动起来。
我把它作为一个先验的测试来运行。希望能帮上忙。
发布于 2017-07-04 08:36:43
On Swift :
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
var from_down = self.view.frame
from_down.origin.y += 50
UIView.animate(withDuration: 0.2, delay: 0.0, options: .autoreverse, animations: {
self.view.frame = from_down
}, completion: nil)
}
https://stackoverflow.com/questions/21469656
复制相似问题