画面上のボタンをランダムに回転させたい。ビュー上でランダムに移動できる特定のパスは定義されていません。
CAKeyframeAnimationを使いたくありません。清潔でシンプルなはずです。
誰かが私を導くことができますか?
画面上のボタンをランダムに回転させたい。ビュー上でランダムに移動できる特定のパスは定義されていません。
CAKeyframeAnimationを使いたくありません。清潔でシンプルなはずです。
誰かが私を導くことができますか?
CGAffineTransform cachedTransform = transformedView.transform;
transformedView.transform = CGAffineTransformIdentity;
// Note each of the (untransformed) points of interest.
CGPoint topLeft = CGPointMake(0, 0);
CGPoint bottomLeft = CGPointMake(0, transformedView.frame.size.height);
CGPoint bottomRight = CGPointMake(transformedView.frame.size.width, transformedView.frame.size.height);
CGPoint topRight = CGPointMake(transformedView.frame.size.width, 0);
// Re-apply the transform.
transformedView.transform = cachedTransform;
// Use handy built-in UIView methods to convert the points.
topLeft = [transformedView convertPoint:topLeft toView:parentView];
bottomLeft = [transformedView convertPoint:bottomLeft toView:parentView];
bottomRight = [transformedView convertPoint:bottomRight toView:parentView];
topRight = [transformedView convertPoint:topRight toView:parentView];
このリンクがあなたに役立つかどうかも確認してください:UIButtonの移動
を使用してボタンのtransform
プロパティをアニメーション化し、ランダムな時間間隔でCGAffineTransformMakeRotation()
と組み合わせます。NSTimer
#define RADIANS(degrees) ((degrees * M_PI) / 180.0)
CGAffineTransform rotateTransform = CGAffineTransformRotate(CGAffineTransformIdentity,
RADIANS(30.0));
myButton.transform = rotateTransform;
NSTimerを使用してこのプロセスを実行し、arc4randomを使用してラジアン単位の角度をランダムに生成します。