【问题标题】:alpha value of uitabbaritemuitabbaritem 的 alpha 值
【发布时间】:2012-06-13 01:43:21
【问题描述】:

我正在尝试弄清楚如何将我的 tabbaritem 图标(图像)设置为 0,以便在它加载到屏幕后给它一个淡入淡出动画......但我只是不知道该怎么做......

这就是我将图像添加到标签栏的方式..

- (void)viewDidAppear:(BOOL)animated
{

    self.button0.image = [UIImage imageNamed:@"icon1.png"];
    self.button1.image = [UIImage imageNamed:@"icon2.png"];
    self.button2.image = [UIImage imageNamed:@"icon3.png"];
    self.button3.image = [UIImage imageNamed:@"icon4.png"];
    self.button4.image = [UIImage imageNamed:@"icon5.png"];
    self.button5.image = [UIImage imageNamed:@"icon1.png"];


}

我将使用类似这样的方法为它们设置动画

[UIView animateWithDuration:0.3f
                              delay:0.0f
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             // Do your animations here
                         }
                         completion:^(BOOL finished){
                             if (finished) {
                                 // Do your method here after your animation.

                             }
                         }];

任何帮助将不胜感激。

更新这是我最新的尝试,但还没有工作..

buttonImage0.image = [UIImage imageNamed:@"icon1.png"];
    buttonImage0.alpha = 0.0;
    self.button0.image = buttonImage0.image;


    [UIView animateWithDuration:0.1f
                          delay:0.0f
                        options:UIViewAnimationOptionTransitionNone
                     animations:^{
                         // Do your animations here.
                         buttonImage0.alpha = 1.0;
                     }
                     completion:^(BOOL finished){
                         if (finished) {
                             // Do your method here after your animation.
                         }
                     }];

【问题讨论】:

  • 我不确定您是否可以设置 alpha。假设有可能,您可以在动画代码块内将 alpha 设置为 0。
  • 我需要在代码块之前设置它,然后在动画中将 alpha 设置为 1(就像图像褪色一样)我想我已经弄清楚了,首先创建 imageview 并设置 alpha 和然后将该图像传递给tabbaritem,然后在代码plock中我将使图像淡入。
  • 完成后我会发布代码,你们可以告诉我它有多糟糕:)

标签: iphone ios uiimageview uiimage alpha


【解决方案1】:

UIButton 是 UIView 的子类。 UIView 有一个 alpha 属性。

试试:

self.button0.alpha = 0.0;
self.button1.alpha = 0.0;
self.button2.alpha = 0.0;
self.button3.alpha = 0.0;
self.button4.alpha = 0.0;
self.button5.alpha = 0.0;

在你看来DidAppear;

然后使用相同的 alpha 属性将缓动函数放入 animateWithDuration 例程中!

【讨论】:

  • 啊抱歉,但这是我的错误命名约定,它是一个 tabbaritem,所以当我尝试你的解决方案时,我得到 在“UITabBarItem *”类型的对象上找不到属性“alpha”
  • 尝试使用 UITabBar 上的 alpha 属性,而不是单独使用每个项目。 UITabBarItem 不继承自 UIView,因此它没有 alpha 属性,但 UITabBar 确实继承自 UIView。
猜你喜欢
  • 2011-06-18
  • 1970-01-01
  • 1970-01-01
  • 2015-06-25
  • 1970-01-01
  • 1970-01-01
  • 2013-01-14
  • 1970-01-01
相关资源
最近更新 更多