2010-08-19 49 views
1

我在我的代码中有一个NSArray设置来显示两个PNG的交替闪烁,我试图设置一段代码,将其设置为隐藏状态,将其移出屏幕,任何事物都不能看到用户。隐藏NSArray - 我该怎么做?

的代码为我的数组是

NSArray *imageArray = [[NSArray alloc] initWithObjects: 
[UIImage imageNamed:@"CONNECTED dark yellow FF CC 00.png"], 
[UIImage imageNamed:@"CONNECTEDR dark yellow FF CC 00.png"], nil]; 

UIImageView *animation = [[UIImageView alloc] initWithFrame: CGRectMake(20, 10, 300, 80)]; 
animation.animationImages = imageArray; 
animation.animationDuration = .8; 
animation.contentMode = UIViewContentModeBottomLeft; 
[self.view addSubview:animation]; 
[animation startAnimating]; 
[animation release]; 
[view release]; 

但是,如果我尝试使用setHidden或.hidden:是的,它似乎并没有隐瞒,喊道该动画没有声明。任何人都可以提出这个答案吗?当然,它盯着我打了一巴掌,但经过几个小时的尝试?现在我承认失败了。

+0

什么时候你想让它消失?用户交互(手势,按钮,..)?时间?重复? – vikingosegundo 2010-08-19 19:38:41

+0

基于用户通过按钮进行交互或基于nsuserdefault设置作为viewdidload的一部分调用方法。 – David26th 2010-08-19 19:52:10

回答

1

你必须保持到animation视图的引用(成员/属性添加到您的视图控制器和右释放前添加像_animationView = animation代码;然后使用_animationView而不是animation当试图隐藏它)。

或者你可以标记设置为这一观点后来被标签找到它...

我希望我明白你的问题所在 - 让我知道,否则。

编辑(后你的第一反应):

在MyViewController.h文件:

class MyViewController : UIViewController { 
    UIImageView *_animationView; 
} 

在MyViewController.m文件:

NSArray *imageArray = [[NSArray alloc] initWithObjects: 
[UIImage imageNamed:@"CONNECTED dark yellow FF CC 00.png"], 
[UIImage imageNamed:@"CONNECTEDR dark yellow FF CC 00.png"], nil]; 

UIImageView *animation = [[UIImageView alloc] initWithFrame: CGRectMake(20, 10, 300, 80)]; 
animation.animationImages = imageArray; 
animation.animationDuration = .8; 
animation.contentMode = UIViewContentModeBottomLeft; 
[self.view addSubview:animation]; 
[animation startAnimating]; 

// Add the next line 
_animationView = animation; 

[animation release]; 
[view release]; 




// Use this method to hide the animation view... 
- (void)hideAnimationView { 
    _animationView.hidden = YES; 
    [_animationView stopAnimating]; 
} 

编辑2
更改.h文件中的声明行(UIImageView *_animationView;

+0

好的,我想我在这里得到你的一般意义,但是你有什么机会可以给我一些代码来更准确地表示你的意思吗?我认为你对自己想要的东西有正确的想法,但是我不会经常以编程的方式建立自己的观点,所以我现在对此感到困惑。 – David26th 2010-08-19 19:03:55

+0

我编辑了我的答案。看看它是否有帮助... – 2010-08-19 19:28:36

+0

错误:Objective-C类'UIView'的静态分配实例 接收.h中的那个.h – David26th 2010-08-19 19:48:52

1

hidden不具有动画效果,因为在YESNO之间没有可能的动画。在布尔逻辑中没有办法表达“有点是,有点不”。

尝试使用字母代替

[aView setAlpha:1.0] // fully opaque 
[aView setAlpha:0.0] // fully transparent 
+0

对此,Cannonade的答案 - 不是Alpha只是改变透明度?如果是这样,我不能使用这个不幸的,因为我实际上需要从屏幕上删除这一点,因为它覆盖了按钮将出现的地方。 – David26th 2010-08-19 19:04:36

+0

alpha大约低于0.1的视图默认情况下不会接收触摸事件。 – 2010-08-19 19:44:12

+0

谢谢。已经尝试过这一点,并怀疑它的工作,但我仍然有一个动画未被宣布的问题。 – David26th 2010-08-19 19:54:15