![](/img/trans.png)
[英]Disabling user interaction for subview interferes with event handling for superview?
[英]Disable user interaction on superview when subView is loaded
我正在創建自定義下拉菜單,並且其功能如我所願,當我單擊select Button時它會彈出,但是當subView在按鈕上彈出時,我想禁用我的超級視圖上的所有用戶交互,即我被困在那里。
當我將菜單作為子視圖添加到超級視圖時,我試圖禁用它,但是它禁用了包括我的子視圖在內的所有觸摸事件。
所以任何人都可以幫助我。
這是我的實現
- (void) showPopUpWithTitle:(NSString *)popupTitle withOption:(NSArray *)arrOptions xy:(CGPoint)point size:(CGSize)size
{
dropDownObject = [[DropDownMenu alloc] initWithTitle:popupTitle options:arrOptions xy:point size:size];
dropDownObject.delegate = self;
[dropDownObject showInView:self.view animated:YES];
[dropDownObject SetBackGroundDropDwon_R:0.0 G:110 B:185.0 alpha:0.60];
}
在這里dropDownObject給我返回了一個自定義tableView,它位於要在屏幕中央彈出的框架內,而與iPhone型號無關
將這個對象添加到另一個類dropDownMenu.m中定義的當前視圖中的方法中的showInView
在這里執行
- (void)showInView:(UIView *)aView animated:(BOOL)animated
{
[aView addSubview:self];
if (animated)
{
[self fadeIn];
}
}
我還實現了視圖動畫fadeIn和fadeOut
- (void)fadeIn
{
self.transform = CGAffineTransformMakeScale(0.5, 0.5);
self.alpha = 0;
[UIView animateWithDuration:.35 animations:^{
self.alpha = 1;
self.transform = CGAffineTransformMakeScale(1, 1);
}];
}
- (void)fadeOut
{
[UIView animateWithDuration:.35 animations:^{
self.transform = CGAffineTransformMakeScale(0.5, 0.5);
self.alpha = 0.0;
} completion:^(BOOL finished) {
if (finished)
{
[self removeFromSuperview];
}
}];
}
將輕擊手勢添加到要添加下拉視圖的視圖中
tapgesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rmovetheoverlay:)];
tapgesture_.delegate=self;
tapgesture_.enabled=YES;
[<viewwhereaddeddropdown> addGestureRecognizer:mTapGestureRecognizer_];
- (void)rmovetheoverlay:(UITapGestureRecognizer *) gestureRecognizer{
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
DLog(@"touch view %@",[touch.view superview]);
DLog(@"touch view %@",touch.view);
if (([touch.view isKindOfClass:[UISearchBar class]] && touch.view==mSearchBar_)||[[touch.view superview] isKindOfClass:[UITableViewCell class]]) {
// prevent recognizing touches on the dropdowntable
return NO;
}
return YES;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.