我一直在嘗試使用下面的方法旋轉按鈕:旋轉的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)];
}];
}
據說這是爲了使按鈕做某種「動搖」,那麼它應該能回到原來的位置 - 但它所做的只是改變按鈕的位置,將其移到僅一側,而在另一次運行該方法時按鈕不會對產生反應。
我的代碼有什麼問題?
謝謝!
編輯2: 我的問題是 - 我該如何做一個按鈕來做一些動作/擺動,例如,編輯spboardboard時擺動應用程序模式。
使用此代碼給我旋轉到左側,從左到右然後從右到左平滑動畫,然後旋轉到原始位置。現在,我希望這不是僅僅旋轉,而是用動畫來完成,就像擺動一樣。
[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){
}
];
謝謝!
爲什麼你在同一時間以相同的旋轉量開始2個動畫? – Wain 2013-04-25 17:01:29
請確切地說明你的意思是「只將它移動到一邊」。也許張貼一些模擬器的截圖? – David 2013-04-25 17:04:47
你可以嘗試下面的帖子,它的UIView,但你可以將其應用於UIButton http://stackoverflow.com/questions/929364/how-to-create-iphones-wobbling-icon-effect – 2013-04-25 17:10:37