Snap an object and exit
I have a view that sets it hidden
when the user deletes the main view. I need the look to fade in and out, so it looks smoother than just fading.
Here is my code so far (it's inside the touch event):
if (!isShowing) {
isShowing = YES;
myView.hidden = YES;
//Needs to fade out here
}
else {
isShowing = NO;
myView.hidden = NO;
//Needs to fade in here
}
+2
a source to share
2 answers
Just wrap your code like this:
[UIView beginAnimations:nil context:NULL];
if (!isShowing) {
isShowing = YES;
myView.hidden = NO
}
else {
isShowing = NO;
myView.hidden = YES
}
[UIView commitAnimations];
or simplify it:
[UIView beginAnimations:nil context:NULL];
isShowing = !isShowing;
myView.hidden = isShowing? NO : YES;
[UIView commitAnimations];
You can also use methods UIView
setAnimationDuration:
, setAnimationCurve:
or, setAnimationBeginsFromCurrentState:
to customize how the view fades in and out.
+5
a source to share