【问题标题】:Not able to call touch event in iphone when clicking on a button单击按钮时无法在 iphone 中调用触摸事件
【发布时间】:2011-04-01 23:19:31
【问题描述】:

当我点击一个按钮时,我需要在 iphone 中调用触摸事件。 我有以下代码没有调用触摸事件

请任何人告诉我如何解决这个问题。

按钮代码如下。

-(void)方法 {

BottomView = [[UIView alloc] init];

btnRefresh =[UIButton buttonWithType:UIButtonTypeCustom]; [btnRefresh setImage:[UIImage imageNamed:@"refresh_icon.png"] forState:UIControlStateNormal]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"blue.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState:UIControlStateNormal]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"ggrey1.png"]stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState:UIControlStateHighlighted]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"ggrey1.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState: UIControlStateSelected]; [btnRefresh addTarget:self action:@selector(KeyboardRefresh:) forControlEvents:UIControlEventTouchUpInside];
[btnRefresh setUserInteractionEnabled:YES]; [btnRefresh setMultipleTouchEnabled:YES];

[BottomView addSubview:btnRefresh];

如果 (self.isPortrait) {

    [btnRefresh setFrame:CGRectMake(71, 0, 40, 6)];

    [BottomView setFrame:CGRectMake(0, 160, 320, 41)];
}
else{

    [btnRefresh setFrame:CGRectMake(94, 0, 61, 8)];

    [BottomView setFrame:CGRectMake(0, 123, 480, 41)];
}

}

上面的方法是调用和

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{ NSLog(@"是"); }

当我点击刷新按钮时没有调用。

谁能帮帮我。 提前致谢

【问题讨论】:

    标签: iphone xcode button uitouch


    【解决方案1】:

    您没有 touchesBegan 的 @selector。相反,您将它用于 KeyboardRefresh。不要在 touchesBegan 中检查按钮是否按下。而是将您的 touchesBegan 替换为:

    -(void)KeyboardRefresh:(id) sender
    { 
        NSLog(@"yes");
    }
    

    【讨论】:

    • 感谢您的留言。但我需要同时调用两者,并且我需要调用 touches move 和 touches end 有什么想法吗?单击刷新按钮时,它必须显示另一个按钮。
    • 我不确定,但是如果您担心按钮,您可能只想为不同的状态创建多种方法。即 UIControlEventTouchUpInside
    猜你喜欢
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 2012-03-14
    • 2020-02-20
    • 1970-01-01
    相关资源
    最近更新 更多