开发者

Show a UILabel for * seconds; other ways than with NSTimer?

Are there any other way of displaying an object/button/whatever,for example 3 seconds开发者_运维技巧 than with an NSTimer?

Could I use an animation to do this?


You may use -performSelector:withObject:afterDelay:, though it uses a timer internally.

[theLabel performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:3];

You cannot use -setHidden: with this method because 1 is not an object, but you can use NSInvocation.

NSInvocation* invoc = [NSInvocation invocationWithMethodSignature:[theLabel methodSignatureForSelector:@selector(setHidden:)]];
[invoc setTarget:theLabel];
[invoc setSelector:@selector(setHidden:)];
BOOL yes = YES;
[invoc setArgument:&yes atIndex:2];
[invoc performSelector:@selector(invoke) withObject:nil afterDelay:3];


You could try:

[UIVIew beginAnimations:nil context:nil];
[UIView setAnimationDelay:3];
[UIView setAnimationDuration:0.1]; //or lower than 0.1
button.hidden = YES;
[UIView commitAnimations];

Marco


Say you have an UIImageView named myImageView: In your .h. file

IBOutlet UIImageView *myImageView;

In the .m file create a method to hide the object:

-(void)hideMyImageView {
    myImageView.hidden = TRUE;
}

Then when you want to hide the Object use this:

[self performSelector:@selector(hideMyImageView) withObject:nil afterDelay:3];

To redisplay the object use this:

myImageView.hidden = FALSE;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜