Dec 1, 2008

Show a view with timer and then disappear

Perhaps it's not the most cleaver way, but seems to work for me.

#import "UIKit/UIKit.h"
#import "Foundation/Foundation.h"
//Note that the lines above apply to my settings of opentoolchain.
@interface aView:UIView
{
NSTimeInterval _interval;
NSInteger _hideCount;
NSTimer _timer;
}
-(void) show;
-(void) hideMe:(id)param;
@end

@implementation aView
-(void) show{
if(_hideCount<0) _hideCount = 0;
_hideCount++;
_timer=[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(hideMe:) userInfo:nil repeats:NO];
[self setUserInteractionEnabled:YES];
return;
}
-(void) hideMe:(id)param
{
if(_hideCount<=1)
{
//Hide it here
[self removeFromSuperview];
}
_hideCount--;
return;
}
@end

No comments: