【问题标题】:multitouch and buttons in same view多点触控和按钮在同一视图中
【发布时间】:2012-02-14 09:43:51
【问题描述】:

嗨,我有一个应用程序 UIViewController,它支持多点触控并且也有一些按钮,我需要的是当用户双击按钮时它会打开一个新视图,而当用户在屏幕上移动手指时它会打开另一个视图。

如果用户将手指放在没有按钮的区域,应用程序可以正常工作,但如果他将手指放在有按钮的区域,则没有任何反应

- (void)viewDidLoad
{
    [super viewDidLoad];
 button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button addTarget:self 
                       action:@selector(openPic:)
             forControlEvents:UIControlEventTouchDownRepeat];
            button.tag = image;
            button.frame = CGRectMake(orInc, inc,  70.0, 95.0);
            [self.view addSubview:button];
]


-(void) openPic:(id)sender  {
    UINavigationController *nav=[[UINavigationController alloc]init];
    PicController *x=[[PicController alloc]init];
    nav.viewControllers=[NSArray arrayWithObject:x];
    [self.navigationController pushViewController:x animated:YES];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UINavigationController *nav=[[UINavigationController alloc]init];
    ViewController *x=[[ViewController alloc]init];
    nav.viewControllers=[NSArray arrayWithObject:x];
    [self.navigationController pushViewController:x animated:YES];
}

【问题讨论】:

    标签: objective-c ios button multi-touch


    【解决方案1】:

    将他的 UIButton 对象的userInteractionEnabled 属性设置为NO 并尝试一下。

    【讨论】:

    • 感谢您的回答,如果我将 userInteractionEnabled 设置为 NO 按钮不再起作用,我需要的是,如果用户双击按钮 openPic 被调用,如果用户只是触摸屏幕,即使按钮 touchesEnded 被调用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多