ios - UIMenuController Has Zero Frame -
i went through every other question on related topic. none helped me far.
i trying show uimenucontroller
on uiview
. therefore subclassed uiview
, implemented required methods already. in uiviewcontroller
instantiate uigesturerecognizer
, add custom uiview
. works fine. can handle long press gesture. uimenucontroller
won't show up!
@interface copyableview : uiview @end @implementation copyableview - (bool)canbecomefirstresponder { nslog(@"_can become 1. responder_"); return yes; } - (bool)canperformaction:(sel)action withsender:(id)sender { nslog(@"_can perform action_"); return (action == @selector(copy:)); } - (void)copy:(id)sender { nslog(@"_copy_"); } @end @interface infoviewcontroller : uiviewcontroller @property (nonatomic, weak) iboutlet copyableview *myview; @end @implementation infoviewcontroller - (void)viewdidload { [super viewdidload]; [self.myview addgesturerecognizer:[[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(handlelongpressgesture:)]]; } - (void)handlelongpressgesture:(uilongpressgesturerecognizer *)recognizer { if (recognizer.state == uigesturerecognizerstatebegan) { nslog(@"__ %i __", [uimenucontroller sharedmenucontroller].menuvisible); [self.myview becomefirstresponder]; uimenuitem *item = [[uimenuitem alloc] initwithtitle:@"copy" action:@selector(copy:)]; [[uimenucontroller sharedmenucontroller] setmenuitems:@[item]]; [[uimenucontroller sharedmenucontroller] settargetrect:cgrectmake(33, 33, 33, 33) inview:self.myview]; [[uimenucontroller sharedmenucontroller] setmenuvisible:yes animated:no]; nslog(@"__ %i __", [uimenucontroller sharedmenucontroller].menuvisible); nslog(@"#### %@ ####", nsstringfromcgrect([uimenucontroller sharedmenucontroller].menuframe)); } }
checking [uimenucontroller sharedmenucontroller].menuvisible
returns true
@ end of method. things seem work. still see nothing happening. frame of uimenucontroller
{{0, 0}, {0, 0}}
cannot understand.
Comments
Post a Comment