Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphone-按下按钮时执行操作_Iphone_Objective C_Button - Fatal编程技术网

iphone-按下按钮时执行操作

iphone-按下按钮时执行操作,iphone,objective-c,button,Iphone,Objective C,Button,例如,我有两个音量按钮(+和-) 我如何实现一些功能,例如,当按住+按钮时,它会以一定的间隔递增音量?(我只感兴趣的是在按下按钮时间隔一段时间做一个动作)首先添加按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(increase)forControlEvents:UIControlEventTouchDown]

例如,我有两个音量按钮(+和-)


我如何实现一些功能,例如,当按住+按钮时,它会以一定的间隔递增音量?(我只感兴趣的是在按下按钮时间隔一段时间做一个动作)

首先添加按钮

 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];
然后写下Button press的方法

-(void)increase
{
//increase the volume here
}

如果不是您想要的解决方案,则意味着添加注释…

首先添加按钮

 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];
然后写下Button press的方法

-(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];
-(void) buttonEvent:(id) sender
{
    UIButton* myButton = (UIButton*) sender;
    if(myButton == myPulseButton)
    {
      [self increaseVolume:myPulseButton.tag];
    }
    else if(myButton == myMinusButton)
    { 
      [self decreaseVolume:myMinusButton.tag];
    }
}
使用按钮添加操作。

myPulseButton.tag = 10;
myMinusButton.tag = 10;
[myPulseButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside]; 

[myMinusButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
-(void) buttonEvent:(id) sender
{
    UIButton* myButton = (UIButton*) sender;
    if(myButton == myPulseButton)
    {
      [self increaseVolume:myPulseButton.tag];
    }
    else if(myButton == myMinusButton)
    { 
      [self decreaseVolume:myMinusButton.tag];
    }
}
执行下面的buttonEvent方法。

myPulseButton.tag = 10;
myMinusButton.tag = 10;
[myPulseButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside]; 

[myMinusButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
-(void) buttonEvent:(id) sender
{
    UIButton* myButton = (UIButton*) sender;
    if(myButton == myPulseButton)
    {
      [self increaseVolume:myPulseButton.tag];
    }
    else if(myButton == myMinusButton)
    { 
      [self decreaseVolume:myMinusButton.tag];
    }
}

假设您有两个按钮,一个用于-,另一个用于+

您可以将间隔信息存储在按钮的标记字段中

在按钮标签属性中安装间隔值。

myPulseButton.tag = 10;
myMinusButton.tag = 10;
[myPulseButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside]; 

[myMinusButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
-(void) buttonEvent:(id) sender
{
    UIButton* myButton = (UIButton*) sender;
    if(myButton == myPulseButton)
    {
      [self increaseVolume:myPulseButton.tag];
    }
    else if(myButton == myMinusButton)
    { 
      [self decreaseVolume:myMinusButton.tag];
    }
}
使用按钮添加操作。

myPulseButton.tag = 10;
myMinusButton.tag = 10;
[myPulseButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside]; 

[myMinusButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
-(void) buttonEvent:(id) sender
{
    UIButton* myButton = (UIButton*) sender;
    if(myButton == myPulseButton)
    {
      [self increaseVolume:myPulseButton.tag];
    }
    else if(myButton == myMinusButton)
    { 
      [self decreaseVolume:myMinusButton.tag];
    }
}
执行下面的buttonEvent方法。

myPulseButton.tag = 10;
myMinusButton.tag = 10;
[myPulseButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside]; 

[myMinusButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
-(void) buttonEvent:(id) sender
{
    UIButton* myButton = (UIButton*) sender;
    if(myButton == myPulseButton)
    {
      [self increaseVolume:myPulseButton.tag];
    }
    else if(myButton == myMinusButton)
    { 
      [self decreaseVolume:myMinusButton.tag];
    }
}

您可以使用计时器来完成此操作。触摸启动时启动计时器。如果计时器过期,请增大或减小音量,然后重新启动计时器。触摸结束后,取消计时器。

您可以使用计时器进行此操作。触摸启动时启动计时器。如果计时器过期,请增大或减小音量,然后重新启动计时器。触摸结束后,取消计时器