UIView核心动画无法在viewdidLoad方法中工作?

问题描述 投票:0回答:2

我是IOS dev的新手,在我的项目中使用核心动画。我希望我的UIVIew默认在主视图之外,并在条件下制作动画。当我在按钮方法中调用它时它工作得很好但是当我在viewdidload中调用它时,程序启动时没有任何反应。

其次我想在我的项目中多次做这个动画像这样:1从右边(屏幕外)到左边(屏幕上的某处),然后是1和2,然后是1 2和3,最后是1 2 3和谁能指导我怎么做?请帮助

//1
//1 2
//1 2 3
//1 2 3 4


- (void)viewDidLoad
{
[super viewDidLoad];

[self animate];

}

-(IBAction)move:(id)sender
{  
[self animate];
}


-(void) animate {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:1];
[UIView setAnimationRepeatAutoreverses:YES];
CGPoint pos;
pos.x = 241.0f;
pos.y = 20.0f;
mover.center = pos;
[UIView commitAnimations];

}
ios objective-c animation uiview core-animation
2个回答
0
投票

请尝试拨打[self animate];这种方法在1秒的延迟视图上确实加载了。


0
投票

试试这个...

dispatch_async(dispatch_get_main_queue(),^ {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationRepeatAutoreverses:YES];
    CGPoint pos;
    pos.x = 241.0f;
    pos.y = 20.0f;
    mover.center = pos;
    [UIView commitAnimations];

});
© www.soinside.com 2019 - 2024. All rights reserved.