我正在尝试将箭头方向更改为向上,以便当它出现时不会阻止我为应用程序设置的顶部栏。这是我用来改变方向的代码:
UIMenuController *menuController = [UIMenuController sharedMenuController];
[menuController setArrowDirection:UIMenuControllerArrowUp];
这是结果,老实说,压力很大:
我的iphone上似乎也是同样的问题。
任何人都可以调查一下吗?谢谢
我正在尝试将箭头方向更改为向上,以便当它出现时不会阻止我为应用程序设置的顶部栏。这是我用来改变方向的代码:
UIMenuController *menuController = [UIMenuController sharedMenuController];
[menuController setArrowDirection:UIMenuControllerArrowUp];
这是结果,老实说,压力很大:
我的iphone上似乎也是同样的问题。
任何人都可以调查一下吗?谢谢
经过几天的研究,我终于找到了改变webview中菜单控制器箭头方向的方法。首先,请在您的视图控制器的viewDidLoad
方法中执行此操作。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuControllerWillShow:) name:UIMenuControllerWillShowMenuNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuControllerWillHide:) name:UIMenuControllerWillHideMenuNotification object:nil];
然后,添加这两个函数,然后箭头方向将始终指向上方,在这种情况下,菜单栏将始终出现在您的文本下方。UIMenuControllerArrowUp;
(同样,如果您希望菜单栏出现在其他位置,您可以更改为任何其他方向)
-(void)menuControllerWillShow:(NSNotification *)notification{
//Remove Will Show Notification to prevent
// "menuControllerWillShow" function to be called multiple times
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIMenuControllerWillShowMenuNotification object:nil];
//Hide the Original Menu View
UIMenuController* menuController = [UIMenuController sharedMenuController];
CGPoint origin = menuController.menuFrame.origin;
CGSize size = menuController.menuFrame.size;
CGRect menuFrame;
menuFrame.origin = origin;
menuFrame.size = size;
[menuController setMenuVisible:NO animated:NO];
//Modify its target rect and show it again to prevent glitchy appearance
menuController.arrowDirection = UIMenuControllerArrowUp;
[menuController setTargetRect:menuFrame inView:self.view];
[menuController setMenuVisible:YES animated:YES];
}
-(void)menuControllerWillHide:(NSNotification *)notification{
//re-register menuControllerWillShow
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuControllerWillShow:) name:UIMenuControllerWillShowMenuNotification object:nil];
}