相关疑难解决方法(0)

UIView无限360度旋转动画?

我正在尝试旋转UIImageView360度,并在线查看了几个教程.我可以让他们都没有工作,没有UIView停止,或跳到一个新的位置.

  • 我怎样才能做到这一点?

我尝试过的最新事情是:

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:0
                 animations:^{
                     imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];
Run Code Online (Sandbox Code Playgroud)

但是如果我使用2*pi,它根本不会移动(因为它是相同的位置).如果我尝试做pi(180度),它可以工作,但如果我再次调用该方法,它会向后旋转.

编辑:

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:0
                 animations:^{
                     [UIView setAnimationRepeatCount:HUGE_VALF];
                     [UIView setAnimationBeginsFromCurrentState:YES];
                     imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];
Run Code Online (Sandbox Code Playgroud)

也不起作用.它会转到180度数,暂停一瞬间,然后在重新0开始之前重新设置为度数.

animation core-animation objective-c uiview ios

244
推荐指数
13
解决办法
15万
查看次数

旋转UIButton

我一直在尝试使用以下方法旋转按钮:

-(IBAction)rotate:(id)sender{
    CGPoint pencilCenter = pencil.center;
    [pencil setCenter:pencilCenter];
    CGFloat floater = 1.0;
    [UIView animateWithDuration:0.7 animations:^(void){
        [pencil setTransform:CGAffineTransformMakeRotation(floater)];
    }];
    [UIView animateWithDuration:0.7 animations:^(void){
        [pencil setTransform:CGAffineTransformMakeRotation(floater)];
    }];
}
Run Code Online (Sandbox Code Playgroud)

这应该使按钮做某种"摇动",然后它应该回到原来的位置 - 但它所做的只是改变按钮的位置,将它移动到只有一侧,并在另一个方法的运行中按钮没有反应在所有.

我的代码有什么问题?

谢谢!

编辑2:我的问题是 - 我如何制作一个按钮来做一些摇摆/摆动,例如编辑sptingboard时的摆动应用模式.

使用此代码可以让我向左旋转,从左到右,然后从右到左平滑动画,然后旋转到原始位置.现在,我希望这不仅仅是旋转,而是通过动画来实现,就像摆动一样.

[UIView animateWithDuration:0.25
                      delay:0.0
                    options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse)
                 animations:^ {
                     pencil.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(30));
                     pencil.transform = CGAffineTransformIdentity;
                 }
                 completion:^(BOOL finished){
                 }
 ];
Run Code Online (Sandbox Code Playgroud)

谢谢!

objective-c uibutton ios

3
推荐指数
1
解决办法
2995
查看次数

标签 统计

ios ×2

objective-c ×2

animation ×1

core-animation ×1

uibutton ×1

uiview ×1