![](/img/trans.png)
[英]iOS - Long Press Gesture Recognizer for UIButton in UITableViewCell
[英]Why is UITableViewCell taking long gesture?
我在UIView
有一個UITableView
,我們稱之為view_A。 有一個UIViewController
,稱之為mainViewController。 里面有一個UIButton
。 在點擊該按鈕時,我將view_A作為子視圖添加到mainViewController的視圖中。 tableview中有幾個菜單項。 問題是tableview沒有正確響應觸摸。 我必須長按細胞才能做出選擇。 它上面沒有添加任何手勢。 沒有其他觀點可以涵蓋它。 這絕對是古怪的,這種行為。 請查看以下代碼並指出可能導致問題的原因。 這是mainViewcontroller中的委托實現/演示:
-(void) showDropDownMenu: (UIButton *) sender
{
UINib *nib = [UINib nibWithNibName:@"DropDownMenuView" bundle:nil];
self.myView = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0];
self.myView.hidden = NO;
self.myView.tag = 101;
self.myView.delegate = self;
self.myView.btnBack.hidden = YES;
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.2;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromBottom ;
transition.delegate = self;
[self.myView.layer addAnimation:transition forKey:nil];
[self.view addSubview:self.myView];
}
-(void) hideDropDownMenu
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.2;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromTop;
transition.delegate = self;
[self.myView.layer addAnimation:transition forKey:nil];
self.myView.tag = 102;
[UIView commitAnimations];
}
-(void) navigateBack
{
}
-(void) themeSelected: (NSIndexPath *) indexPath
{
NSLog(@"%ld",(long)indexPath.item);
themeNumber = [NSString stringWithFormat:@"%li",(indexPath.row+1)];
[self setUpTheme];
}
這是cell.h文件的實現:
@interface ThemeTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *themeName;
@property (weak, nonatomic) IBOutlet UIImageView *themePreview;
這是cell.m文件的實現:
#import "ThemeTableViewCell.h"
@implementation ThemeTableViewCell
- (void)awakeFromNib {
// Initialization code
//ORIGINAL 82
self.clipsToBounds = YES;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
更新:我記錄了手勢,並以某種方式結果長按手勢設置為單元格。
您是否禁用了cell imageview userInteraction,如果沒有嘗試此cell.yourImageView.userInteractionEnabled = NO
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.