I have the following code:
visitSite.hidden = YES;
For some reason, when I click a UIButton and call this piece of code, the visitSite button does not hide.
The code is within this block:
-(IBAction)welcomeButtonPressed:(id)sender {
[UIButton beginAnimations:@"welcomeAnimation" context:NULL];
[UIButton setAnimationDuration:1.5];
[UIButton SetAnimationDidStopSelector:@selector(nowHideThisSiteButton:finished:context:)];
[UIButton setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
((UIView *)sender).hidden = YES;
[UIButton commitAnimations];
}
and the stop selector below:
-(void)nowHideThisSiteButton:(NSString *)animationID finished:(BOOL *)finished context:(void *)context {
visitSite.hidden = YES;
}
I’ve also tried [visitSite setHidden:YES]; and that fails as well. ALSO I’ve noticed that the setAnimationDidStopSelector does not get called at all.
Also, visitSite (when NSLogged) equals:
<UIButton: 0x1290f0; frame = (0 0; 320 460); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x1290f0>>
visitSite.hidden (when NSLogged) equals: NULL
Any more ideas? 🙁
There are a few mistakes in your code.
The
hiddenproperty of UIView is NOT animatable. When this animation block runs, your button will vanish, but it will not fade/animate. The appropriate way to fade out a UIView is to animate itsalphaproperty from 1.0 to 0.0 like this:myView.alpha = 1.0;
[UIView beginAnimations:@”Fade” context:NULL];
myView.alpha = 0.0;
[UIView commitAnimations];
Here is a list of animatable UIView properties
setAnimationDidStopSelectordoes not get called because you have not set the animation delegate. You have properly specified a didStopSelector, which tells the UIView class what message to send when animation is complete. However, you haven’t specified what to send this message to. The animation block has no idea about your object. Just add this line inside the animation block:[UIView setAnimationDelegate:self];
(Replace self with whatever object you want to receive the didStopSelector)
As others has stated, your button is nil because it hasn’t been hooked up properly in Interface Builder. In your .h file, you should have
@property (nonatomic, retain) IBOutlet UIButton * visitSite;. Then in Interface Builder, click your controller, switch to the Connections display, and drag the open circle thing over to your button. That should do it. See the Interface Builder help guide for more info on that.