我复制了这个教程; https://www.youtube.com/watch?v=uTbi_0LFxm0
我认为该代码已被弃用,因为vid是在4年前发布的。特别是因为它使用了旧的“appdidfinishlaunching”方法。这可行吗?
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
//this was a uiwindow in .h
@synthesize whatsup=whatsup;
- (void)viewDidLoad
{
UIImage * image = [UIImage imageNamed:@"sexy.jpg"];
UIImageView * imgView = [[UIImageView alloc]initWithImage:image];
[imgView setFrame:(CGRect){{0,0},image.size}];
[imgView setCenter:(CGPoint){160,240}];
[whatsup addSubview:imgView];
CABasicAnimation * fullRotation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue=[NSNumber numberWithFloat:0];
fullRotation.toValue=[NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 6;
fullRotation.repeatCount= 1;
[imgView.layer addAnimation:fullRotation forKey:@"360"];
[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.
}
@end
什么都没有真正加载。我应该把它搞定吗?你认为这有效吗?
答案 0 :(得分:2)
我会尽力回答这个问题;请尊重我们,考虑下面的建议。
NSParameterAssert(image);
。[super viewDidLoad];
是你应该做的第一件事,而不是最后一件事。现在提供建议。
StackOverflow不存在关于从其他网站上抓取的代码片段的博客,而是讨论特定和明确定义的主题。
因此,您的问题可以是:
CABasicAnimation
弃用?答案:不。-viewDidLoad
是否已正确实施?答案:不。最后,这是我对代码的解释:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage * image = [UIImage imageNamed:@"test.png"];
NSParameterAssert(image);
UIImageView * imgView = [[UIImageView alloc]initWithImage:image];
[imgView setCenter:self.view.center];
[self.view addSubview:imgView];
CABasicAnimation * fullRotation=[CABasicAnimation
animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue=@(0);
fullRotation.toValue=@(2*M_PI);
fullRotation.duration = 6;
fullRotation.repeatCount= 1;
[imgView.layer addAnimation:fullRotation forKey:@"360"];
}