移动时旋转 imageView [英] rotate an imageView While moving it

查看:30
本文介绍了移动时旋转 imageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个名为 image 的 UIView,我试图让它在我上下移动视图时旋转,这是我到目前为止所做的,但它使图片旋转而不向下:

So I have an UIView called image, and i am trying to get it to rotate while i am moving the view up and down,here is what I've done so far,but it makes the picture rotate and not go down:

{
    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;
        }
    }
}

任何帮助将不胜感激(:

any help would be much appreciated (:

推荐答案

尝试用这个方法旋转 imageview

try rotating imageview with this method

        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];

这篇关于移动时旋转 imageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆