UIMenuController:如图显示
<h4>要使用UIMenuController 需要满足一个条件:这个控件可以成为第一响应者(UIView的直接父类就是UIResponder,所以都能满足).然后需要重写UIResponder下的两个方法:
-(BOOL)canBecomeFirstResponder{
return YES;
}
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{
//这个方法就是UIMenuController的响应,可以根据action的名字来返回YES或者NO
}
<h4>OK,解决了响应问题之后,我们需要拿到UIMenuController,并告诉它响应位置 响应后出现的位置 及 响应什么.具体实现:
- (void)responder{
UIMenuController *menu =[UIMenuController sharedMenuController];
UIMenuItem *dianzan =[[UIMenuItem alloc]initWithTitle:@"点赞" action:@selector(DianZan:)];
UIMenuItem *huifu =[[UIMenuItem alloc]initWithTitle:@"回复" action:@selector(HuiFu:)];
UIMenuItem *jubao =[[UIMenuItem alloc]initWithTitle:@"举报" action:@selector(JuBao:)];
menu.menuItems =@[dianzan,huifu,jubao];
[menu setMenuVisible:YES animated:YES];
}
-(void)DianZan:(id)sender{
NSLog(@"%s",__func__);
}
-(void)HuiFu:(id)sender{
NSLog(@"%s",__func__);
}-(void)JuBao:(id)sender{
NSLog(@"%s",__func__);
}
注: UIResponder的介绍,很快更新.