移动它时旋转imageView

时间:2014-02-19 23:48:26

标签: ios objective-c while-loop rotation

所以我有一个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;
        }
    }
}

任何帮助将不胜感激(:

2 个答案:

答案 0 :(得分: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];

enter image description here

答案 1 :(得分:0)

你采取了错误的做法。你应该使用新的基于块的UIView动画方法,比如animateWithDuration:animations:和它的表兄弟。

您可以同时为旋转和移动设置动画。

如果您可以将开发限制为iOS 7,则可以使用基于关键帧的新动画方法,这些方法可以让您轻松完成定时动画序列。