gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:27:19 26 4
gpt4 key购买 nike

我有一个从第一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com