【问题标题】:Animate an ImageView from the ViewController in Xcode (objective-c)?从 Xcode 中的 ViewController 为 ImageView 设置动画(objective-c)?
【发布时间】:2016-06-11 06:11:48
【问题描述】:

我一直在尝试为我在 Main.StoryBoard 上创建的 UIView 设置动画。

我在我的 ViewController.h 文件中为它创建了插座。

@property (strong, nonatomic) IBOutlet UIImageView *Player;

我尝试的动画是:

 - (void) PlayerMoves {
    [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveLinear animations: self.Player.center = CGPointMake(self.Player.center.x, self.Player.center.y -50) completion:nil]; 
}

无论我做什么,它都会告诉我我有一个错误。

将“CGPoint”(又名“struct CGPoint”)发送到不兼容类型“void (^ _Nonnull)(void)”的参数

【问题讨论】:

标签: ios objective-c uiview uiviewcontroller uiviewanimation


【解决方案1】:

您应该将 blocks 传递给 animateWithDuration。一个例子:

[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
    // your animation here
    self.Player.center = CGPointMake(self.Player.center.x, self.Player.center.y -50)
} completion:nil];

该方法中的参数animations(void (^)(void))的类型。您需要阅读更多关于 Objective-C 中的块以及如何使用它们的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    相关资源
    最近更新 更多