Iphone 为什么这个按钮没有响应
对按钮定义进行以下更改:Iphone 为什么这个按钮没有响应,iphone,objective-c,Iphone,Objective C,对按钮定义进行以下更改: UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 300.0, 43.0, 43.0)]; [imageView setBackgroundColor:[UIColor clearColor]]; [imageView setImage:[UIImage imageNamed:@"test.png"]]; [self.view addSubvie
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 300.0, 43.0, 43.0)];
[imageView setBackgroundColor:[UIColor clearColor]];
[imageView setImage:[UIImage imageNamed:@"test.png"]];
[self.view addSubview:imageView];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView animateWithDuration: 0.2f
delay: 0.0f
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState
animations: ^(void){[imageView setFrame:CGRectMake(0.0, 350.0, 43.0, 43.0)];}
completion: nil];
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(100, 0, 100, 30)];
[button setTitle:@"Button" forState:UIControlStateNormal];
[self.view addSubview:button];
您的方法应该如下所示:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
我希望这会有帮助。尝试修改动画的持续时间:见下文
-(IBAction)buttonHandle:(id)sender
{
}
在options属性中,我添加了值UIViewAnimationOptionAllowUserInteraction,如果单击不起作用,则无法触摸按钮 编写代码
[UIView animateWithDuration: 0.2f
delay: 0.0f
options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState
animations: ^(void){[imageView setFrame:CGRectMake(0.0, 350.0, 43.0, 43.0)];}
completion: nil];
在方法的末尾。我认为您希望在按钮上执行操作,所以请尝试以下代码
[self.view bringSubviewToFront:button];
嗨,你有什么问题。你能解释清楚吗?我把上面的代码添加到一个viewController中,当运行时,按钮不能被触摸。当触摸按钮时,应用程序崩溃了?您根本看不到按钮?添加UIViewAnimationOptionAllowUserInteraction添加UIViewAnimationOptionAllowUserInteraction,我已经完成了
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(100, 0, 100, 30)];
[button setTitle:@"Button" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
-(IBAction)buttonPressed:(id)sender
{
//put code here you want to perform action on button
}