2013-09-16 256 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

is dismissTutorial當你按下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