我有一个动画从第一个控制器开始,当我从另一个控制器调用该控制器时,动画无法启动。
这是我的HomeController.m
:
//
// HomeController.m
// /
#import "HomeController.h"
#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>
#import "HomeController.h"
#include <AudioToolbox/AudioToolbox.h>
@interface HomeController (){
}
@property (strong, nonatomic) IBOutlet UILabel *accendi;
// create the label animated
@property (strong, nonatomic) IBOutlet UIImageView *arrow;
// create the image animated
@end
@implementation HomeController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:(BOOL)animated];
[self frecciaanimata];
}
-(void) frecciaanimata {
CGRect arrowFrame = self.arrow.frame;
arrowFrame.origin.x = arrowFrame.size.height;
CGRect accendiFrame = self.accendi.frame;
accendiFrame.origin.x = accendiFrame.size.height;
[UIView animateWithDuration:0.7
delay:1.2
options: UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse
animations:^{
_arrow.frame = CGRectMake(140, 244, 14, 28);
_accendi.frame = CGRectMake(80, 247, 63, 21);
}
completion:^(BOOL finished){
NSLog(@"Done!");
//create animation block
}];
}
// end of animation block
@end
当其他控制器通过按下按钮来调用此控制器(HomeController
)时,是否可以启动动画?
答案 0 :(得分:1)
将[self frecciaanimata];
更改为:
[self performSelector:@selector(frecciaanimata) withObject:nil afterDelay:0.01];
<强>更新强>
对于最近从backGround回击时处理动画的请求,请执行以下操作:
在您的ViewDidLoad
方法中:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(someMethod)
name:UIApplicationDidBecomeActiveNotification object:nil];
然后按如下方式添加someMethod
:
-(void) someMethod{
[self performSelector:@selector(frecciaanimata) withObject:nil afterDelay:0.01];
}