Articles Tagged 'setAnimationDelegate'

setAnimationDidStopSelector: different uses and advanced

In most cases, or because we are used or because we have seen in tutorials and in some texts, we use the setAnimationDidStopSelector in this manner:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
nil context : NULL ] ; [UIView beginAnimations: nil context: NULL];
1.5 ] ; [UIView setAnimationDuration: 1.5];
UIViewAnimationCurveEaseInOut ] ; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
self ] ; [UIView setAnimationDelegate: self];
@selector ( removeView ) ] ; [UIView setAnimationDidStopSelector: @ selector (removeView)];

; myView.alpha = 0;

; [UIView commitAnimations];

/ /

void ) removeView { - (Void) {removeView
; [MyView removeFromSuperview];
}

come delegato e tramite la setAnimationDidStopSelector gli invia un messaggio removeView quando l'animazione è terminata. In the code above the setAnimationDelegate set self as delegate and through setAnimationDidStopSelector sends a message removeView when the animation is finished. The code itself is correct, however, makes use of a message definition ( removeView ) that could be omitted. Now, here is the same code, with the same effect, without the message removeView :

1
2
3
4
5
6
7
8
9
nil context : NULL ] ; [UIView beginAnimations: nil context: NULL];
1.5 ] ; [UIView setAnimationDuration: 1.5];
UIViewAnimationCurveEaseInOut ] ; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
myView ] ; [UIView setAnimationDelegate: myView];
@selector ( removeFromSuperview ) ] ; [UIView setAnimationDidStopSelector: @ selector (removeFromSuperview)];

; myView.alpha = 0;

; [UIView commitAnimations];

! The interesting thing about this approach is that myView could be a subclass of UIView ! It may therefore be a custom class with our own messages and, as stated, easily callable from setAnimationDidStopSelector . In addition, the setAnimationDidStopSelector selectors agree with parameters:

1
2
3
4
5
6
7
8
9
nil context : NULL ] ; [UIView beginAnimations: nil context: NULL];
1.5 ] ; [UIView setAnimationDuration: 1.5];
UIViewAnimationCurveEaseInOut ] ; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
myView ] ; [UIView setAnimationDelegate: myView];
@selector ( myMessage : param1 : ) ] ; [UIView setAnimationDidStopSelector: @ selector (myMessage: param1:)];

; myView.alpha = 0;

; [UIView commitAnimations];

This example can be extended to all cases here where we set a delegate, Atro is not a pointer to an instance of any object.

Continued ...