隐藏NSArray - 我该怎么办?

时间:2010-08-19 15:24:34

标签: iphone ipad nsarray hidden

我的代码中有一个NSArray设置,显示两个PNG交替闪烁,我正在尝试设置一段代码,将其设置为隐藏状态,将其移出屏幕,任何东西都可以让它看不见用户。

我的数组的代码是

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:YES,它似乎没有隐藏并且声称没有声明动画。任何人都可以建议这个答案吗?当然,在经过几个小时的尝试之后,它盯着我一巴掌?我现在承认失败了。

3 个答案:

答案 0 :(得分:1)

hidden不具有动画功能,因为YESNO之间不存在动画。在布尔逻辑中无法表达“有点是和有点”。

尝试使用alpha代替

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

答案 1 :(得分:1)

您必须保留对animation视图的引用(向视图控制器添加成员/属性,并在发布之前添加_animationView = animation之类的代码;然后使用{{1}当试图隐藏它时,而不是_animationView

或者您可以为此视图设置标签,稍后通过标记找到它...

我希望我能理解你的问题 - 请让我知道。

编辑(在您第一次回复后):

在MyViewController.h文件中:

animation

在MyViewController.m文件中:

class MyViewController : UIViewController {
    UIImageView *_animationView;
}

编辑2
更改了.h文件(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 :(得分:0)

您是否尝试将动画 alpha上的UIImageView属性设置为零?如果您在animation block内修改此属性,则会进行动画淡出。