1. <legend id='oXlp7'><style id='oXlp7'><dir id='oXlp7'><q id='oXlp7'></q></dir></style></legend>

    2. <tfoot id='oXlp7'></tfoot>

        <bdo id='oXlp7'></bdo><ul id='oXlp7'></ul>

    3. <small id='oXlp7'></small><noframes id='oXlp7'>

      <i id='oXlp7'><tr id='oXlp7'><dt id='oXlp7'><q id='oXlp7'><span id='oXlp7'><b id='oXlp7'><form id='oXlp7'><ins id='oXlp7'></ins><ul id='oXlp7'></ul><sub id='oXlp7'></sub></form><legend id='oXlp7'></legend><bdo id='oXlp7'><pre id='oXlp7'><center id='oXlp7'></center></pre></bdo></b><th id='oXlp7'></th></span></q></dt></tr></i><div id='oXlp7'><tfoot id='oXlp7'></tfoot><dl id='oXlp7'><fieldset id='oXlp7'></fieldset></dl></div>

        如何为 UIControl/UIButton 动画从一种状态到另一种状态的过渡?

        时间:2023-07-07
        • <legend id='VfcmM'><style id='VfcmM'><dir id='VfcmM'><q id='VfcmM'></q></dir></style></legend>
        • <tfoot id='VfcmM'></tfoot>
          • <bdo id='VfcmM'></bdo><ul id='VfcmM'></ul>
              <tbody id='VfcmM'></tbody>
                <i id='VfcmM'><tr id='VfcmM'><dt id='VfcmM'><q id='VfcmM'><span id='VfcmM'><b id='VfcmM'><form id='VfcmM'><ins id='VfcmM'></ins><ul id='VfcmM'></ul><sub id='VfcmM'></sub></form><legend id='VfcmM'></legend><bdo id='VfcmM'><pre id='VfcmM'><center id='VfcmM'></center></pre></bdo></b><th id='VfcmM'></th></span></q></dt></tr></i><div id='VfcmM'><tfoot id='VfcmM'></tfoot><dl id='VfcmM'><fieldset id='VfcmM'></fieldset></dl></div>

              1. <small id='VfcmM'></small><noframes id='VfcmM'>

                1. 本文介绍了如何为 UIControl/UIButton 动画从一种状态到另一种状态的过渡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 UIButton 可以在突出显示时更改图像.从 UIControlStateHighlight 过渡到 UIControlStateNormal 时,我希望突出显示的图像慢慢淡入正常图像.是否有捷径可寻?

                  I have a UIButton that changes image on highlight. When transitioning from UIControlStateHighlight to UIControlStateNormal, I want the highlighted image to slowly fade back into the normal image. Is there an easy way to do this?

                  推荐答案

                  我最终继承了 UIButton.这是实现文件代码.我取出了一些特定于应用程序的东西,所以我没有测试过这个确切的代码,但应该没问题:

                  I ended up subclassing UIButton. Here's the implementation file code. I took some app-specific stuff out, so I haven't tested this exact code, but it should be fine:

                  #import "SlowFadeButton.h"
                  
                  @interface SlowFadeButton ()
                  
                  @property(strong, nonatomic)UIImageView *glowOverlayImgView; // Used to overlay glowing animal image and fade out
                  
                  @end
                  
                  @implementation SlowFadeButton
                  
                  
                  
                  -(id)initWithFrame:(CGRect)theFrame mainImg:(UIImage*)theMainImg highlightImg:(UIImage*)theHighlightImg
                  {
                      if((self = [SlowFadeButton buttonWithType:UIButtonTypeCustom])) {
                  
                          self.frame = theFrame;
                  
                          if(!theMainImg) {
                              NSLog(@"Problem loading the main image
                  ");
                          }
                          else if(!theHighlightImg) {
                              NSLog(@"Problem loading the highlight image
                  ");
                          }
                  
                          [self setImage:theMainImg forState:UIControlStateNormal];
                          self.glowOverlayImgView = [[UIImageView alloc] initWithImage:theHighlightImg];
                          self.glowOverlayImgView.frame = self.imageView.frame;
                          self.glowOverlayImgView.bounds = self.imageView.bounds;
                  
                          self.adjustsImageWhenHighlighted = NO;
                      }
                  
                      return self;
                  }
                  
                  
                  -(void)setHighlighted:(BOOL)highlighted
                  {
                      // Check if button is going from not highlighted to highlighted
                      if(![self isHighlighted] && highlighted) {
                          self.glowOverlayImgView.alpha = 1;
                          [self addSubview:self.glowOverlayImgView];
                      }
                      // Check if button is going from highlighted to not highlighted
                      else if([self isHighlighted] && !highlighted) {
                          [UIView animateWithDuration:1.0f
                                           animations:^{
                                               self.glowOverlayImgView.alpha = 0;
                                           }
                                           completion:NULL];
                      }
                  
                      [super setHighlighted:highlighted];
                  }
                  
                  -(void)setGlowOverlayImgView:(UIImageView *)glowOverlayImgView
                  {
                      if(glowOverlayImgView != _glowOverlayImgView) {
                          _glowOverlayImgView = glowOverlayImgView;
                      }
                  
                      self.glowOverlayImgView.alpha = 0;
                  }
                  
                  @end
                  

                  您也可以从 [self imageForState:UIControlStateHighlighted] 中提取突出显示的图像并使用它,它应该可以正常工作.主要是确保adjustsImageWhenHighlighted = NO,然后重写setHighlighted:方法.

                  You could also just pull the highlighted image from [self imageForState:UIControlStateHighlighted] and use that, it should work the same. The main things are to make sure adjustsImageWhenHighlighted = NO, and then overriding the setHighlighted: method.

                  这篇关于如何为 UIControl/UIButton 动画从一种状态到另一种状态的过渡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UserDefault 保存按钮状态 下一篇:UIButton 标题更改为默认值

                  相关文章

                2. <small id='v5pbt'></small><noframes id='v5pbt'>

                  <legend id='v5pbt'><style id='v5pbt'><dir id='v5pbt'><q id='v5pbt'></q></dir></style></legend>
                3. <tfoot id='v5pbt'></tfoot>

                    • <bdo id='v5pbt'></bdo><ul id='v5pbt'></ul>
                      <i id='v5pbt'><tr id='v5pbt'><dt id='v5pbt'><q id='v5pbt'><span id='v5pbt'><b id='v5pbt'><form id='v5pbt'><ins id='v5pbt'></ins><ul id='v5pbt'></ul><sub id='v5pbt'></sub></form><legend id='v5pbt'></legend><bdo id='v5pbt'><pre id='v5pbt'><center id='v5pbt'></center></pre></bdo></b><th id='v5pbt'></th></span></q></dt></tr></i><div id='v5pbt'><tfoot id='v5pbt'></tfoot><dl id='v5pbt'><fieldset id='v5pbt'></fieldset></dl></div>