Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.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_Objective C_Ios Animations - Fatal编程技术网

iOS如何在屏幕外启动图像并在屏幕上设置动画

iOS如何在屏幕外启动图像并在屏幕上设置动画,ios,objective-c,ios-animations,Ios,Objective C,Ios Animations,我试图将图像从屏幕左侧滑到屏幕上,并停在视图的中心点。如果可能的话,我想把它保持在y位置(即图片设置在故事板上) 我正在阅读本教程,但它是用swift编写的,我无法在objective-c中完成相同的作业 它说要设置屏幕外的视图(在swift中): 然后(用swift)设置动画: 然而,我不能像在swift中那样操纵目标c中的center.x 我已经尝试过通过改变边界来调整图像在viewwillbeen中的初始位置,但没有成功 编辑: 以下是我试图让它在屏幕上定位的内容: self.headi

我试图将图像从屏幕左侧滑到屏幕上,并停在视图的中心点。如果可能的话,我想把它保持在y位置(即图片设置在故事板上)

我正在阅读本教程,但它是用swift编写的,我无法在objective-c中完成相同的作业

它说要设置屏幕外的视图(在swift中):

然后(用swift)设置动画:

然而,我不能像在swift中那样操纵目标c中的center.x

我已经尝试过通过改变边界来调整图像在viewwillbeen中的初始位置,但没有成功

编辑:

以下是我试图让它在屏幕上定位的内容:

self.heading.center = CGPointMake(-200, self.heading.center.y);
无论我将x位置设置为多负,视图仍将显示在屏幕上。实际上,无论我将x位置设置为什么,视图都不会沿x方向移动。我还尝试设置帧

视图中心的x坐标在Objective-C中不可直接指定。相反,尝试整体设置中心点。在您的示例中,这可能看起来像这样:

[UIView animateWithDuration:0.5 animations:^{
    CGFloat newCenterX = self.heading.center.x + self.view.bounds.size.width;
    self.heading.center = CGPointMake(newCenterX, self.heading.center.y);
}];

尝试使用CGAffineTransformMakeTransform:

      [UIView animateKeyframesWithDuration:5
                               delay:0
                               options:UIViewKeyframeAnimationOptionCalculationModeLinear
                               animations:^{

                               view.transform = CGAffineTransformMakeTranslation(550, -40);
                               }];

没有解释如何将其从屏幕上删除。请参见“我的编辑”。@lostintranslation,这样您就不能通过编程影响视图的位置了?您是否在情节提要或其他方面启用了它的superview?如果是这样的话,任何应用于视图的自动布局约束都会阻止您自己操纵它的框架。很确定我有自动布局和约束。尽管这也带来了关于如何跨不同设备和横向/纵向对齐和约束视图的各种其他问题。所以没有办法使用动画和约束?顺便说一句,谢谢你的帮助,真的很感激。而且动画确实会移动视图。不知道这是否重要。但是,最初将视图设置为屏幕外是不起作用的。
[UIView animateWithDuration:0.5 animations:^{
    CGFloat newCenterX = self.heading.center.x + self.view.bounds.size.width;
    self.heading.center = CGPointMake(newCenterX, self.heading.center.y);
}];
      [UIView animateKeyframesWithDuration:5
                               delay:0
                               options:UIViewKeyframeAnimationOptionCalculationModeLinear
                               animations:^{

                               view.transform = CGAffineTransformMakeTranslation(550, -40);
                               }];