uibutton をある位置から別の位置にランダムに移動することに疑問があります。位置は静的です。全部で 8 つのポジションがあります。タイマーを使用して、dis メソッドを呼び出します。
2 に答える
            2        
        
		
- これらの 8 つの位置を 8 つの CGRects に保存します。
 - 次に、; を使用して 1 から 8 までの乱数を生成し
int r = arc4random() % 8ます。 - using
switchステートメントはCGRect、r に応じてボタンの を設定します。 
于 2013-05-08T11:27:12.250   に答える
    
    
            0        
        
		
.h ファイルに次を追加します。
    @property (nonatomic, strong) NSTimer *timer;
    @property (nonatomic, strong) NSMutableArray *framesArray;
.m ファイルに次を追加します。
あなたのviewDidLoadメソッドで:
    _timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(changeButtonPositions) userInfo:nil repeats:YES];
   _framesArray = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithCGRect:CGRectMake(x_1, y_1, w_1, h_1)],[NSValue valueWithCGRect:CGRectMake(x_2, y_2, w_2, h_2)],[NSValue valueWithCGRect:CGRectMake(x_3, y_3, w_3, h_3)],[NSValue valueWithCGRect:CGRectMake(x_4, y_4, w_4, h_4)],[NSValue valueWithCGRect:CGRectMake(x_5, y_5, w_5, h_5)],[NSValue valueWithCGRect:CGRectMake(x_6, y_6, w_6, h_6)],[NSValue valueWithCGRect:CGRectMake(x_7, y_7, w_7, h_7)],[NSValue valueWithCGRect:CGRectMake(x_8, y_8, w_8, h_8)], nil];
changingButtonのアニメーション化を開始する場合は、次のようにします。
[_timer fire];
このメソッドを追加します。
- (void) changeButtonPositions{
    int number = arc4random() % 8;
    changingButton.frame = [[_framesArray objectAtIndex:number] CGRectValue];
}
アニメーションを終了したいときは、
[_timer invalidate];
    于 2013-05-08T11:35:46.377   に答える