views - Problems Removing Subview from SuperView - Objective-C -
not sure why isn't working remove added subview parent view. want removed if longpress action ended. tested nslog , know gestures registering ended, it's not removing subview.
-(void)addsubview:(uilongpressgesturerecognizer *)gesture { nsarray *subviewarray = [[nsbundle mainbundle] loadnibnamed:@"overlayview" owner:self options:nil]; uiview *subview = [subviewarray objectatindex:0]; if (gesture.state == uigesturerecognizerstatebegan) { [self.view addsubview:subview]; } if (gesture.state == uigesturerecognizerstateended) { [subview removefromsuperview]; } }
desired functionality:
longpress starts: add subview.
longpress ends: remove subview.
i hope resolve issue declaring uiview *subview in .h file , putting below lines in viewdidload:
nsarray *subviewarray = [[nsbundle mainbundle] loadnibnamed:@"overlayview" owner:self options:nil]; uiview *subview = [subviewarray objectatindex:0];
and then:
-(void)addsubview:(uilongpressgesturerecognizer *)gesture { if (gesture.state == uigesturerecognizerstatebegan) { [self.view addsubview:subview]; } if (gesture.state == uigesturerecognizerstateended) { [subview removefromsuperview]; } }
Comments
Post a Comment