隐藏 NSArray - 我该怎么做?

发布于 2024-09-15 07:09:07 字数 739 浏览 1 评论 0原文

我的代码中有一个 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 它似乎不会隐藏并大声喊出动画未声明。谁能提出这个问题的答案?当然,它盯着我打了一巴掌,但经过几个小时的尝试之后?我暂时承认失败了。

I've got an NSArray setup in my code to display two PNG's alternately flashing, I'm trying to setup a piece of code that sets it to a hidden status, moves it off screen, anything to get it out of sight of the user.

The code for my array is

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];

However if I try using a setHidden or .hidden:YES it doesn't seem to hide and cries out that animation is not declared. Can anyone suggest the answer to this? Sure its staring me slap bang in the face but after a few hours of trying? I've admitted defeat for now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌生 2024-09-22 07:09:07

您必须保留对 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;)

You have to keep a reference to the animation view (add a member/property to your view controller and add a code like _animationView = animation right before releasing it; and then use the _animationView instead of animation when trying to hide it).

Or you might set a tag to this view and find it by tag later...

I hope that I've understood your problem right - let me know otherwise.

EDIT (after your first response):

In MyViewController.h file:

class MyViewController : UIViewController {
    UIImageView *_animationView;
}

In MyViewController.m file:

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];
}

EDIT 2:
Changed the declaration line in .h file (UIImageView *_animationView;)

猫烠⑼条掵仅有一顆心 2024-09-22 07:09:07

hidden 不可设置动画,因为 YESNO 之间不可能有动画。没有办法用布尔逻辑来表达“有点是,有点否”。

尝试使用 alpha 代替

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

hidden is not animate-able, as there is no animation possible between YES and NO. There is no way to express "A bit YES and a bit NO" in boolean logic.

Try using alpha instead

[aView setAlpha:1.0] // fully opaque
[aView setAlpha:0.0] // fully transparent
-残月青衣踏尘吟 2024-09-22 07:09:07

您是否尝试过设置 alpha 动画属性 UIImageView 为零?如果您在 动画块,它将执行动画淡出。

Have you tried setting the alpha property on your animation UIImageView to zero? If you modify this property inside an animation block, it will do an animated fade out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文