Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.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
Ios 设置UIButton状态的动画,以在点击时淡入淡出_Ios_Iphone_Objective C_Ios7 - Fatal编程技术网

Ios 设置UIButton状态的动画,以在点击时淡入淡出

Ios 设置UIButton状态的动画,以在点击时淡入淡出,ios,iphone,objective-c,ios7,Ios,Iphone,Objective C,Ios7,我想要一个ui按钮在点击时淡入高亮显示状态,然后在用户将手指从按钮上移开时淡出。我尝试使用transitionWithView来实现这一点,但这只适用于在用户移除手指时淡出高亮显示状态 这是我的密码。谢谢 [UIView transitionWithView:view duration:.2 options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction anim

我想要一个
ui按钮
在点击时淡入高亮显示状态,然后在用户将手指从按钮上移开时淡出。我尝试使用
transitionWithView
来实现这一点,但这只适用于在用户移除手指时淡出高亮显示状态

这是我的密码。谢谢

  [UIView transitionWithView:view duration:.2 options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction animations:nil completion:nil]; 
你试过这个吗

[UIView animateWithDuration:0.2 animations:^{
    button.highlighted = YES;
}];

首先创建UIButton的一个新子类,在我的示例中,我称它为“MyButton”

并使用:

接触开始了

触碰

触摸移动

为了实现您所期望的褪色效果,如下所示:

#import <UIKit/UIKit.h>

@interface MyButton : UIButton

@end



#import "MyButton.h"

@implementation MyButton

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [UIView animateWithDuration:0.2 animations:^{
          self.viewForBaselineLayout.alpha = 0;
    }];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [UIView animateWithDuration:0.2 animations:^{
        self.viewForBaselineLayout.alpha = 1;
    }];

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [UIView animateWithDuration:0.2 animations:^{
        self.viewForBaselineLayout.alpha = 1;
    }];

}
@end

这不会使它淡入淡出好吧,我只是这样做了,但当点击按钮时,它会消失,并且不会显示高亮显示的状态图像。谢谢。那你到底想要什么?标题?我想在按钮状态之间淡入淡出我想要的不是仅仅进入按钮按下的突出显示状态,而是淡入淡出过渡到突出显示状态,然后当你移除手指时淡出回到正常状态突出显示的效果是什么?变色?褪色动画您只需覆盖“-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated”,并将“self.viewForBaselineLayout.alpha=0;”更改为“[self-setHighlighted:YES];”
@interface ViewController ()

@end

@implementation ViewController



- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    MyButton *button = [[MyButton alloc]init];
    [button setFrame:CGRectMake(100, 100, 100, 100)];
    [button setTintColor:[UIColor blackColor]];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitle:@"HelloThere" forState:UIControlStateNormal];
    [self.view addSubview:button];
}