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

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.CSS);@import url(/css/cuteeditor.css);#PRagma -mark点击模态视图外的空白处隐藏模态视图

- (void)viewDidAppear:(BOOL)animated

{

[superviewDidAppear:animated];

_tapRecognizer= [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(handleTapBehind:)];

[_tapRecognizersetNumberOfTapsRequired:1];

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

[self.view.windowaddGestureRecognizer:_tapRecognizer];

[_tapRecognizersetDelegate:(id<UIGestureRecognizerDelegate>)self];

}

- (void)handleTapBehind:(UITapGestureRecognizer*)sender

{

if(sender.state==UIGestureRecognizerStateEnded) {

// passing nil gives us coordinates in the window

CGPointlocation = [senderlocationInView:nil];

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

if([[UIDevicecurrentDevice].systemVersionfloatValue] >=8.0f) {

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.viewpointInside:[self.viewconvertPoint:locationfromView:self.view.window]withEvent:nil]) {

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

[self.view.windowremoveGestureRecognizer:sender];

[selfdismissViewControllerAnimated:YEScompletion:nil];

}

}

}

#pragma mark - UIGestureRecognizer Delegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer

{

returnYES;

}

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

{

returnYES;

}

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

{

returnYES;

}

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

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航