1
我有一個UIPanGestureRecognizer。它工作正常。我做了一個if語句,所以當有人觸摸這張圖片時,它會是alpha 0.7,它會大1.5倍。 alpha工作正常,但是當我輸入CAAffineTransformMakeScale方法時,我的圖像不會移動。當我想調整它時,我的PanGestureRecognizer不會移動
這是我的代碼:
- (IBAction)Bloemen:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
if (UIGestureRecognizerStateBegan)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.1];
[UIView setAnimationDuration:0.4];
bloemen.alpha = 0.7f;
bloemen.transform = CGAffineTransformMakeScale(1.5,1.5);
[UIView commitAnimations];
}
if (UIGestureRecognizerStateEnded) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.1];
[UIView setAnimationDuration:0.1];
bloemen.alpha = 1.0f;
bloemen.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
}
如果您使用自動佈局,我可以告訴你如何動畫約束條件的變化(因爲移動後的視圖會在重新應用約束條件時返回到原始位置,比如當你做最後的動畫時),但是除非你使用自動佈局,否則不要想問題。上面代碼片段中的關鍵問題在於'if'子句,如下所述。 – Rob 2013-04-23 23:18:48