I’m creating an animated UIButton to simulate an insterstitial banner, but it’s not getting the event UIControlEventTouchUpInside. Here is my code:
-(void)insertInterstitialBannerAtView:(UIView *)mainView {
if ([self bannerExists]) {
bannerButton = [UIButton buttonWithType:UIButtonTypeCustom];
[bannerButton setFrame:CGRectMake(0, 480, 320, 43)];
[bannerButton setImage:[UIImage imageNamed:@"389.png"] forState:UIControlStateNormal];
[bannerButton setEnabled:YES];
[mainView addSubview:bannerButton];
[mainView bringSubviewToFront:bannerButton];
[bannerButton addTarget:self
action:@selector(buttonPushed)
forControlEvents:UIControlEventTouchUpInside];
[UIView animateWithDuration:2.0
animations:^(void) {
[bannerButton setFrame:CGRectMake(0, 417, 320, 43)];
}
completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 delay:3.0 options:UIViewAnimationTransitionNone animations:^(void){
[bannerButton setFrame:CGRectMake(0, 480, 320, 43)];
}
completion:^(BOOL finished) {
}];
}];
}
}
-(IBAction)buttonPushed{
NSLog(@"Interstitial Pushed");
}
-(BOOL)bannerExists{
BOOL returnValue = FALSE;
NSArray *names = [URLFORSPLASH componentsSeparatedByString:@"/"];
NSString *fileName = [names lastObject];
NSString *cacheFolder = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [cacheFolder stringByAppendingPathComponent:fileName];
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath] ) {
returnValue = TRUE;
}
return returnValue;
}
Does anybody know what’s wrong?
Regards,
Claudio
ios disables interactions during an animation. From the UIView documentation: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW111
“During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.)”
If you’re targeting ios 5, you might be able to get away with intercepting touches in the parent view and then checking to see if they’re where the animation is/was when the touch was intercepted.