Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 此动画代码是否已弃用?_Ios_Deprecated_Cabasicanimation - Fatal编程技术网

Ios 此动画代码是否已弃用?

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

我复制了这个教程

我认为这段代码是不推荐的,因为视频是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
没有什么东西真的很重。我应该把它关掉吗?你认为这有用吗


我会尽我所能回答这个问题;请允许我们考虑以下建议

  • 不,没有不推荐的
  • 这篇文章写得很糟糕,但这离题了
  • 确保您的图像“sexy.jpg”是可执行文件的一部分。一种简单的方法是添加
    NSParameterAssert(图像)加载后
  • [super viewDidLoad]是你应该做的第一件事,而不是最后一件
  • 现在听听你的建议

    StackOverflow并不是为了在博客上发布从其他网站上刮取的代码片段,而是讨论特定的、定义良好的主题

    因此,你的问题可以是:

  • iOS 7中是否已弃用
    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?)发件人