Ios 此动画代码是否已弃用?
我复制了这个教程 我认为这段代码是不推荐的,因为视频是4年前发布的,特别是因为它使用了旧的“appdidfinishlaunching”方法。这可行吗Ios 此动画代码是否已弃用?,ios,deprecated,cabasicanimation,Ios,Deprecated,Cabasicanimation,我复制了这个教程 我认为这段代码是不推荐的,因为视频是4年前发布的,特别是因为它使用了旧的“appdidfinishlaunching”方法。这可行吗 #import "ViewController.h" @interface ViewController () @end @implementation ViewController //this was a uiwindow in .h @synthesize whatsup=whatsup; - (void)viewDidLoad
#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
没有什么东西真的很重。我应该把它关掉吗?你认为这有用吗
我会尽我所能回答这个问题;请允许我们考虑以下建议
NSParameterAssert(图像)代码>加载后
[super viewDidLoad]代码>是你应该做的第一件事,而不是最后一件
cabasicanition
?回答:没有-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"];
}
查看文档。相对于您为项目选择的部署目标,正在使用的类或方法是否标记为已弃用?通常,对每年都在变化的API使用4年的教程可能会导致问题;代码是旋转整个视图还是仅仅旋转图像?还有一种方法可以锚定旋转点吗?(1a)旋转图像:
[imgView.layer addAnimation…
(1b)要旋转整个视图,请使用[self.view.layer addAnimation:…
(2)要锚定动画,您需要锚定层本身。例如imgView.layer.anchorPoint=CGPointZero;
-(iAction)segue:(segue?)发件人