隐藏 NSArray - 我该怎么做?
我的代码中有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须保留对
animation
视图的引用(向视图控制器添加成员/属性,并在释放它之前添加类似_animationView =animation
的代码;然后使用尝试隐藏时使用_animationView
而不是animation
)。或者您可以为此视图设置一个标签,稍后通过标签找到它...
我希望我已经正确理解了您的问题 - 否则请告诉我。
编辑(在您第一次回复后):
在 MyViewController.h 文件中:
在 MyViewController.m 文件中:
编辑 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 ofanimation
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:
In MyViewController.m file:
EDIT 2:
Changed the declaration line in .h file (
UIImageView *_animationView;
)hidden
不可设置动画,因为YES
和NO
之间不可能有动画。没有办法用布尔逻辑来表达“有点是,有点否”。尝试使用 alpha 代替
hidden
is not animate-able, as there is no animation possible betweenYES
andNO
. There is no way to express "A bit YES and a bit NO" in boolean logic.Try using alpha instead
您是否尝试过设置 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.