3

次の方法を使用してボタンを回転させようとしています。

-(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)];
    }];
}

これは、ボタンにある種の「シェイク」を行わせることになっています。その後、元の位置に戻るはずですが、ボタンの位置を変更して、ボタンを片側だけに移動し、別のメソッドを実行すると、ボタンが全く反応ません。

私のコードの問題は何ですか?

ありがとう!

EDIT 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){
                 }
 ];

ありがとう!

4

4 に答える 4

7

「QuartzCore/QuartzCore.h」をインポートして試してみると、

CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.delegate = self;
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 1.7;
fullRotation.repeatCount = 2;
[btnTemp.layer addAnimation:fullRotation forKey:@"360"];
于 2013-04-27T12:53:05.283 に答える
0

さて、ドキュメントは次のように述べています:「...指定されたアニメーションは別のスレッドですぐに開始されます...」。現在、すべての UIKit コードはスレッドセーフではありません。そのため、UI セッター (setTransform、setCenter) を完了ブロック (別のスレッドで実行) から呼び出して、performSelectorOnMainThread:withObject:.

于 2013-04-25T19:44:45.040 に答える