Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 移动图像视图时旋转图像视图_Ios_Objective C_While Loop_Rotation - Fatal编程技术网

Ios 移动图像视图时旋转图像视图

Ios 移动图像视图时旋转图像视图,ios,objective-c,while-loop,rotation,Ios,Objective C,While Loop,Rotation,因此,我有一个名为image的ui视图,我试图在上下移动视图时使其旋转,这是我迄今为止所做的,但它使图片旋转而不是下降: { return centerY - height / 2 <= 10 || centerY + height/ 2 >= self.view.bounds.size.height - 10; } -(void)moveUpDownTimerCallback { [UIView commitAnimations]; vertica

因此,我有一个名为image的
ui视图,我试图在上下移动视图时使其旋转,这是我迄今为止所做的,但它使图片旋转而不是下降:

{
    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=self.view.bounds.size.height-10;
}
-(无效)moveUpDownTimerCallback
{
[UIView委员会];
垂直速度+=加速度;
度+=度变化;
CGSize sz=image.bounds.size;
image.transform=CGAffineTransformMakeRotation(度*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+垂直速度);
如果([自相碰撞:image.center.y+垂直速度图像高度:
image.bounds.size.height]){
加速度=0;
[自上下移动:0];
}
否则{
image.center=newCenter;
}
}
-(void)上下移动:(int)v速度
{
垂直速度=垂直速度;
如果(垂直速度!=0 | |加速度!=0){
如果(计时器==nil)
计时器=[NSTimer scheduledTimerWithTimeInterval:0.05
目标:自我
选择器:@selector(moveUpDownTimerCallback)
用户信息:无
重复:是];
}
}
否则{
如果(计时器!=nil){
[计时器失效];
定时器=零;
}
}
}

任何帮助都将不胜感激(:

您采取了完全错误的方法。您应该使用新的基于块的UIView动画方法,如animateWithDuration:animations:和它的近亲

可以同时设置旋转和移动的动画


如果您可以将开发限制在iOS 7上,那么有一些新的基于关键帧的动画方法可以让您非常轻松地执行动画的定时序列。

尝试使用此方法旋转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];

向下是指向下扩展?还是只是将视图保持原样并更改其Y坐标?嘿,非常感谢您的快速响应,这段代码可以在xcode 4中使用?还是仅在5中使用?请回答最后一个问题,这一行:UIImageView imageView=(UIImageView*)[cell ViewWith Tag:56];它说“使用未声明的标识符单元格,在这一行:CABasicAnimation animation=[CABasicAnimation animationWithKeyPath:@”transform.rotation.z“];它说:“初始化器元素不是编译时常量”抱歉,如果这是一个愚蠢的问题…为想要旋转的图像制作一个出口。然后删除这一行。”“UIImageView*imageView=(UIImageView*)[cell viewWithTag:56];”并假设您的imageView为“self.imageview1”,将这一行“[imageView.layer addAnimation:animation forKey:@”rotation”;”替换为“[self.imageview1.layer addAnimation:animation forKey:@”rotation”];“1重要提示:所需图像应位于您试图移动的视图内。只有在这种情况下,您才能获得动画。