开发者

Why is this button does not respond? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_高级运维 Closed 11 years ago.
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];


Try amending your animateWithDuration: see below

[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];

Within the options property I've added the value UIViewAnimationOptionAllowUserInteraction


If you are not able touch the button (if the click is not working) then

write the code

[self.view bringSubviewToFront:button];

at the end of the method.


I think you want to action perform on button so try this code.

      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
}


Make below change in Button definition:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

And you method should be like below:

-(IBAction)buttonHandle:(id)sender
{
}

I hope it will be helpful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜