Xcode对象正在向手指移动,这是新的



大家好,我是新来的
我有一个UIimageview
我知道UITouch的坐标是多少
现在我想要球(UIImageView)朝它移动。
我试着想办法做到这一点
使用CGPoint
但我想不出任何能正常工作的方法
我该怎么做?(我在网上找不到答案)

    - (void)viewDidLoad
{
    [super viewDidLoad];
    [self play];
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(play) userInfo:nil repeats:YES];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    ballvelocity = [touch locationInView:self.view];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    ballvelocity = [touch locationInView:self.view];
}
-(void) play{
    [UIView animateWithDuration:3 animations:^{
        ball.center = CGPointMake(ballvelocity.x, ballvelocity.y);
    }];
}

如果你擅长区块。。

可以使用创建动画

UIView animateWithDuration:(NSTimeInterval) animations:^(void)>

其他

UIView beginAnimations:(NSString *) context:(void *)

在这两种动画方法中,都可以设置

[imageView setCenter:yourlocation];

这将使其动画化到该位置。

有关设置视图动画的更多信息,请点击此处:https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816

最新更新