Objective-C - UIControlEventTouchUpInside没有被触发?

时间:2012-04-19 17:58:37

标签: objective-c uibutton

我正在创建一个动画UIButton来模拟一个insterstitial横幅,但它没有得到事件UIControlEventTouchUpInside。这是我的代码:

-(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;
}

有人知道什么是错的吗?

此致 克劳迪奥

1 个答案:

答案 0 :(得分:0)

ios禁用动画期间的交互。来自UIView文档:http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW111

“在动画期间,对于正在设置动画的视图暂时禁用用户交互。(在iOS 5之前,整个应用程序都禁用了用户交互。)”

如果您的目标是ios 5,您可以在父视图中拦截触摸,然后检查它们是否是截取触摸时动画的位置。