iphone - 同时按下按钮
问题描述:
比方说我有两个音量按键做一个动作(+和 - )iphone - 同时按下按钮
我如何能实现的东西,例如按住+按钮时一样,这将提高了音量递增间隔? (我只是有兴趣在一个区间做一个动作在按下按钮时)
答
您可以为此使用计时器。触摸开始时启动计时器。如果定时器到期,请增大或减小音量并重新启动定时器。当触摸结束时,取消定时器。
答
首先添加按钮...
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(increase)forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
然后写按钮移到按方法。
-(void)increase
{
//increase the volume here
}
,如果它是不是你想要的方式添加注释的解决方案......
答
假设你有两个按钮,一个是 - 和其他的+,
你可以存储在间隔信息您的按钮的标记字段
在您的按钮标记属性中安装间隔值。
myPulseButton.tag = 10;
myMinusButton.tag = 10;
添加文字与按钮。
[myPulseButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
[myMinusButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
实现如下面的方法buttonEvent。
-(void) buttonEvent:(id) sender
{
UIButton* myButton = (UIButton*) sender;
if(myButton == myPulseButton)
{
[self increaseVolume:myPulseButton.tag];
}
else if(myButton == myMinusButton)
{
[self decreaseVolume:myMinusButton.tag];
}
}