因此,这会显示一个略微透明的图像,右上角有一个“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 :(得分:0)
在视图中添加标记:overlay.tag = OVERLAY_TAG;
-(void)showTutorial
{
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView *overlay = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
overlay.tag = OVERLAY_TAG;
.....
}