ios - 不将动画重新启动到根 Controller

标签 ios objective-c core-animation quartz-core

我有一个从第一个 Controller 开始的动画,当我从另一个 Controller 调用此 Controller 时,动画不会开始。 这是我的 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

当其他 Controller 调用此 Controller (HomeController) 时,我可以通过按下按钮来启动动画吗?

最佳答案

[self frecciaanimata]; 更改为:

[self performSelector:@selector(frecciaanimata) withObject:nil afterDelay:0.01];

更新:

最近请求处理后台返回时的动画,执行如下操作:

在您的 ViewDidLoad 方法中:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(someMethod)
                                             name:UIApplicationDidBecomeActiveNotification object:nil];

然后添加someMethod如下:

-(void) someMethod{
    [self performSelector:@selector(frecciaanimata) withObject:nil afterDelay:0.01];

}

关于ios - 不将动画重新启动到根 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20299070/

相关文章:

使用 ARC 进行 iOS 内存管理

ios - 一组动画完成后切换到不同 View

iphone - 在 textView 中,当我点击完成按钮时,键盘没有退出

background - 从多任务处理回来后如何恢复 CAAnimation

uiview - 如何通过触摸移动 UIView 使其保持在圆圈内?

ios - 如何在启动时实现像 UBER 应用程序文本这样的动画

ios - 解析 JSON 它在 Swift 中不起作用

c# - 使用自定义单元配件的 Monotouch - 如何判断选择了哪一行

ios - UITextField 获得焦点,然后由于在 textFieldShouldReturn 中返回 YES 而立即失去焦点

iPhone(iOS 5)从横向强制纵向并返回