虽然移动它旋转的ImageView的(rotate an imageView While movin

2019-10-19 09:29发布

所以我有一个UIView所谓形象,我试图让它转动,而我移动视图上下,这里是我到目前为止已经完成,但它使得画面旋转,而不是往下走:

{
    return centerY - height / 2 <= 10 ||
    centerY + height/ 2 >= self.view.bounds.size.height - 10;
}

-(void)moveUpDownTimerCallback
{
    [UIView commitAnimations];
    verticalSpeed += acceleration;
    degrees+=degreechange;
    CGSize sz = image.bounds.size;
    image.transform = CGAffineTransformMakeRotation(degrees * M_PI/180),image.layer.anchorPoint =  
    CGPointMake(rotPointx/sz.width,rotPointy/sz.height);rotPointy = image.center.y;      
   rotPointx = image.center.x;

    CGPoint newCenter = CGPointMake(image.center.x, image.center.y + verticalSpeed);
    if ([self hasCollided: image.center.y + verticalSpeed imageHeight:           
    image.bounds.size.height]) {     
        acceleration = 0;
        [self moveUpDown: 0];

    }
    else {
        image.center = newCenter;
    }
}

-(void)moveUpDown:(int) vSpeed
{
    verticalSpeed = vSpeed;
    if (verticalSpeed != 0 || acceleration != 0) {
       if (timer == nil) 
          timer =[NSTimer scheduledTimerWithTimeInterval:0.05
       target:self
       selector:@selector(moveUpDownTimerCallback)
       userInfo:nil
       repeats:YES];
       }
    }
    else {
        if (timer != nil) {
            [timer invalidate];
            timer = nil;
        }
    }
}

任何帮助将非常感激 (:

Answer 1:

尝试用此方法旋转的ImageView

        CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        animation.fromValue = @0.0f;
        animation.toValue = @(2*M_PI);
        animation.duration = 1.0f;             // this might be too fast
        animation.repeatCount = HUGE_VALF;     // HUGE_VALF is defined in math.h so import it
        [self.imageview1.layer addAnimation:animation forKey:@"rotation"];

和移动视图,此方法

CGRect frameBottomview1 = self.yourview.frame;
frameBottomview1.origin.y = 300;
   [UIView animateWithDuration:0.7 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                    [self.yourview setFrame:frameBottomview1 ];

                } completion:nil];



Answer 2:

您正在完全错误的做法。 您应该使用新的基于块的UIView的动画方法,如animateWithDuration:动画:和它的表兄弟。

您可以在同一时间动画旋转和运动。

如果你可以限制你发展到iOS 7有新的基于关键帧的动画方法,让你做动画的时间顺序很容易。



文章来源: rotate an imageView While moving it