|
属性声明:
UIWindow *_window;
#define XWWindowHeight 20
#define XWDuration 0.5
#define XWDelay 1.5
#define XWFont [UIFont systemFontOfSize:12]
方法实现:
+ (void)showMessage:(NSString *)msg image:(UIImage *)image
{
if (_window) return;
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.titleLabel.font = XWFont;
btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[btn setTitle:msg forState:UIControlStateNormal];
[btn setImage:image forState:UIControlStateNormal];
_window = [[UIWindow alloc] init];
_window.backgroundColor = [UIColor blackColor];
_window.windowLevel = UIWindowLevelAlert;
_window.frame = CGRectMake(0, -XWWindowHeight, [UIScreen mainScreen].bounds.size.width, XWWindowHeight);
btn.frame = _window.bounds;
[_window addSubview:btn];
_window.hidden = NO;
[UIView animateWithDuration:XWDuration animations:^{
CGRect frame = _window.frame;
frame.origin.y = 0;
_window.frame = frame;
}completion:^(BOOL finished) {
[UIView animateWithDuration:XWDuration delay:XWDelay options:kNilOptions animations:^{
CGRect frame = _window.frame;
frame.origin.y = -XWWindowHeight;
_window.frame = frame;
} completion:^(BOOL finished) {
_window = nil;
}];
}];
}
|