2013-09-16 3 views
0

Таким образом, это вызывает изображение, которое слегка прозрачно с кнопкой «X» в верхнем правом углу, что отклоняет изображение. По какой-то причине это не работает! Любые идеи о том, как убрать изображение?Изображение всплывающее окно не будет отменено, когда я нажимаю кнопку

Проверьте кнопку, возможно, я не создавал селектор правильно ...

#define OVERLAY_TAG 997 
-(void)showTutorial 
{ 
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; 
    UIView *overlay = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    overlay.backgroundColor = [UIColor clearColor]; 
    overlay.userInteractionEnabled = YES; 
    [keyWindow addSubview:overlay]; 
    UITapGestureRecognizer * tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self 
                        action:@selector(dismissTutorial)]; 
    CGFloat border = 10; 
    CGRect frame = overlay.bounds; 

    // 20 is the status bar height (sorry for using the number) 
    frame = CGRectMake(border, border + 20, frame.size.width - border * 2, frame.size.height - border * 2 - 20); 

    // the black view in the example is probably a scroll view 
    UIView *blackView = [[UIView alloc] initWithFrame:frame]; 
    blackView.backgroundColor = [UIColor blackColor]; 
    blackView.alpha = 0.7; 
    [overlay addSubview:blackView]; 

    // add all the subviews for your tutorial 
    /*UIImage* image = [UIImage imageNamed:@"slide_image_3.png"]; 
    UIImageView* info = [[UIImageView alloc] initWithImage:image]; 
    info.frame = CGRectMake(0, 0, 200, 150); 
    [blackView addSubview:info];*/ 

    UIImage* image4 = [UIImage imageNamed:@"close_img.png"]; 
    dismissTut = [[UIButton alloc] initWithFrame:CGRectMake(250, 18, 26, 26)]; 
    [dismissTut setBackgroundImage:image4 forState:UIControlStateNormal]; 
    [dismissTut addTarget:self action:@selector(dismissTutorial) 
     forControlEvents:UIControlEventTouchUpInside]; 
    [dismissTut setShowsTouchWhenHighlighted:YES]; 

    [blackView addSubview:dismissTut]; 

    // make it appear with an animation 
    [UIView animateWithDuration:0.3 
        animations:^{blackView.alpha = 0.6;} 
        completion:^(BOOL finished){[overlay addGestureRecognizer:tapRecognizer];}]; 
} 

-(void)dismissTutorial 
{ 
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; 
    UIView *overlay = [keyWindow viewWithTag:OVERLAY_TAG]; 
    [UIView animateWithDuration:0.3 
        animations:^{ 
         overlay.alpha = 0.0; 
        } 
        completion:^(BOOL finished){ 
         [overlay removeFromSuperview]; 
        }]; 
} 
+0

istrackTutorial вызывается при нажатии кнопки X или нет? – incmiko

+0

Любые другие жесты, используемые для других видов? – Wain

+0

Я вызвал метод в методе действия кнопки. – Lalalalalala

ответ

0

Добавить тег к вашему мнению: overlay.tag = OVERLAY_TAG;

-(void)showTutorial 
{ 
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; 
    UIView *overlay = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    overlay.tag = OVERLAY_TAG; 
..... 
} 
+0

Удивительный! Я так и сказал, но не мог понять. Спасибо за помощь! – Lalalalalala

Смежные вопросы