簡體   English   中英

呈現模態視圖控制器時呈現視圖控制器響應觸摸事件

[英]Presenting view controller response touch events when modal view controller is presented

這是代碼:

UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil];
UIViewController *presentedViewController = [myStoryboard instantiateViewControllerWithIdentifier:@"IdentifierName"];
presentedViewController.modalPresentationStyle = UIModalPresentationFormSheet;

presentingViewController presentViewController:presentedViewController animated:NO completion:nil];

presentingViewController的視圖不會響應任何觸摸事件,但是我希望它接受觸摸事件,我該怎么辦? 感謝任何建議!

這是預期的行為,應該是您在大多數應用中看到的。 Apple的App Store應用程序確實允許您在模式表單之外點擊以將其關閉,因此,在有限的范圍內,有一些先例可以接受。 如果您的設計絕對需要,請考慮在提供的視圖控制器中設置和拆除基於窗口的手勢識別器。

例如,要實現輕拍從外部到關閉的行為,請在viewDidAppear:配置輕viewDidAppear:手勢識別器。 您可以在viewWillDisappear:上將其刪除viewWillDisappear:如果在調用時它仍然存在。

在輕敲處理程序中,您想獲取輕敲在窗口坐標中的位置,即:

CGPoint tapPoint = [recognizer locationInView:nil];

然后,您可以對幾何圖形進行一些檢查,以查看是否在模態表示的視圖上或外部(在與您的呈現視圖控制器相對應的變暗區域上)發生了敲擊。 UIView有一個pointInside:withEvent:方法可能對此有所幫助。

這是呈現ViewController的簡單方法...

  ViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
  [self presentViewController:view animated:YES completion:nil];

享受代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM