![](/img/trans.png)
[英]UIBarButtonItems of a UIToolbar hiding when presenting UIActivityViewController
[英]Warning when presenting UIActivityViewController
当我使用下面的代码呈现UIActivityController
,它会呈现,但控制台显示“ Warning: Attempt to present <UIActivityViewController: 0x7f8788e7aed0> on <MyApp.CustomTableViewController: 0x7f8788e3db60> which is already presenting (null)
”。
@IBAction func shareImage(sender: AnyObject) {
let images: [UIImage] = [image.image!]
let activityViewController = UIActivityViewController(activityItems: images, applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)
}
该函数由UILongPressGestureRecognizer
。 请注意,我正在使用具有以下层次结构的故事板:
TabBarController
> (Relationship) > NavigationController
> (Relationship) > TableViewController
> (Show) > TableViewController
> (Show) > ViewController
。
演示发生在最后一个 ViewController 上。
我很确定这是关于层次结构的,哪个控制器当前正在呈现(也许是如何呈现)以及哪个控制器负责呈现UIActivityViewController
。
编辑
UILongPressGestureRecognizer
触摸事件被多次调用,导致警告
很难从您的问题中说出来,但是在发生这种情况时是否还提供了其他一些视图控制器? 例如和行动表或其他?
在任何情况下试试这个:
if self.presentedViewController != nil {
self.dismissViewControllerAnimated(false, completion: {
[unowned self] in
self.presentViewController(activityViewController, animated: true, completion: nil)
})
}else{
self.presentViewController(activityViewController, animated: true, completion: nil)
}
我收到相同的错误消息,因为 UILongPressGestureRecognizer 多次调用我的选择器。 现在我在 UILongPressGestureRecognizer 状态结束时调用 UIActivityViewController。
@objc func longTouch(gestureRecognizer: UILongPressGestureRecognizer){
print("long touch")
if gestureRecognizer.state != .ended {
print("long touch not ended")
return
}
//open UIActivityViewController
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.