FormSheet式模态视图,点击模态视图外隐藏模态视图的方法_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > FormSheet式模态视图,点击模态视图外隐藏模态视图的方法

FormSheet式模态视图,点击模态视图外隐藏模态视图的方法

 2015/3/16 11:44:48  罕见  程序员俱乐部  我要评论(0)
  • 摘要:#pragma-mark点击模态视图外的空白处隐藏模态视图-(void)viewDidAppear:(BOOL)animated{[superviewDidAppear:animated];_tapRecognizer=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(handleTapBehind:)];[_tapRecognizersetNumberOfTapsRequired:1]
  • 标签:方法 for

#pragma -mark 点击模态视图外的空白处隐藏模态视图


- (void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

    _tapRecognizer = [[UITapGestureRecognizer allocinitWithTarget:selfaction:@selector(handleTapBehind:)];

    [_tapRecognizer setNumberOfTapsRequired:1];

    _tapRecognizer.cancelsTouchesInView = NO//So the user can still interact with controls in the modal view

    [self.view.window addGestureRecognizer:_tapRecognizer];

    [_tapRecognizer setDelegate:(id<UIGestureRecognizerDelegate>)self];

}


- (void)handleTapBehind:(UITapGestureRecognizer *)sender

{

    if (sender.state == UIGestureRecognizerStateEnded) {

        

        // passing nil gives us coordinates in the window

        CGPoint location = [sender locationInView:nil];

        

        // swap (x,y) on iOS 8 in landscape

        if (SYSTEM_VERSION_MORE_THAN_8) {

            if (UIInterfaceOrientationIsLandscape([UIApplicationsharedApplication].statusBarOrientation)) {

                location = CGPointMake(location.y, location.x);

            }

        }

        

        // convert the tap's location into the local view's coordinate system, and test to see if it's in or outside. If outside, dismiss the view.

        if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.windowwithEvent:nil]) {

            

            // remove the recognizer first so it's view.window is valid

            [self.view.window removeGestureRecognizer:sender];

            [self dismissViewControllerAnimated:YES completion:nil];

        }

    }

}


#pragma mark - UIGestureRecognizer Delegate


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

{

    return YES;

}


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer

{

    return YES;

}


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

{

    return YES;

}

 

转载:http://my.oschina.net/CreeveLiu/blog/347913 

 

 

 

上一篇: 如果在这些领域创业,或许能得到盖茨基金会投资 下一篇: 没有下一篇了!
发表评论
用户名: 匿名