我的应用中有Navigation Bar
。
如下图所示
我希望View来自上行并覆盖整个UINavigationBar
,它可以是UIView
。然后再次通过动画进入上面。
答案 0 :(得分:4)
您应该继承UIAlertView并在主视图上显示它吗?
见下面的代码
#import <Foundation/Foundation.h>
@interface MyAlertView : NSObject
@property (nonatomic,retain) UIButton *alertBtn;
@property (nonatomic,retain) UIButton *closeBtn;
@property (nonatomic,retain) NSTimer *timer;
@property(nonatomic) int loadTime;
-(void) setAlert :(UIWindow *)currentWindow;
-(void) showAlert :(NSString *)alertText;
-(void)closeAlert;
@end
#import "MyAlertView.h"
@implementation MyAlertView
@synthesize loadTime;
@synthesize closeBtn,alertBtn,timer;
BOOL timessss=FALSE;
-(void) setAlert :(UIWindow *)currentWindow{
loadTime=3;
self.alertBtn=[[UIButton alloc] init];
self.alertBtn.titleLabel.numberOfLines=2;
self.closeBtn=[[UIButton alloc] init];
self.closeBtn.hidden=YES;
self.alertBtn.titleLabel.adjustsFontSizeToFitWidth=YES;
[[self alertBtn] setBackgroundImage:[UIImage imageNamed:@"orangeBar"] forState:UIControlStateNormal];
[[self closeBtn] setBackgroundImage:[UIImage imageNamed:@"cross-1"] forState:UIControlStateNormal];
[[self closeBtn] addTarget:self action:@selector(cancelAlert) forControlEvents:UIControlEventTouchUpInside];
[[self alertBtn] addTarget:self action:@selector(cancelAlert) forControlEvents:UIControlEventTouchUpInside];
[self.alertBtn setFrame:CGRectMake(0, 20.0f, 320.0f, 50.0f)];
[self.closeBtn setFrame:CGRectMake(294, 17.0f, 15.0f, 15.0)];
[self.closeBtn setHidden:YES];
[self.alertBtn setHidden:YES];
[currentWindow addSubview:self.alertBtn];
//[self.alertBtn addSubview:self.closeBtn];
//[currentWindow addSubview:self.closeBtn];
}
-(void) cancelAlert{
[UIView transitionWithView:self.alertBtn
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:NULL
completion:NULL];
[self.alertBtn setHidden:YES];
[self.closeBtn setHidden:YES];
[timer invalidate];
timessss=FALSE;
}
-(void) showAlert :(NSString *)alertText{
if(alertBtn.isHidden);
else return;
[self.alertBtn setTitle:alertText forState:UIControlStateNormal];
[UIView transitionWithView:self.alertBtn
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromTop
animations:NULL
completion:NULL];
[UIView transitionWithView:self.closeBtn
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromTop
animations:NULL
completion:NULL];
[self.alertBtn setHidden:NO];
timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(closeAlert) userInfo:nil repeats:YES];
[timer fire];
}
-(void)closeAlert{
if (timessss) {
[UIView transitionWithView:self.alertBtn
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:NULL
completion:NULL];
[self.alertBtn setHidden:YES];
[self.closeBtn setHidden:YES];
[timer invalidate];
timessss=FALSE;
}
else{
timessss=TRUE;
[self.closeBtn setHidden:NO];
}
}
@end
在全局定义属性时调用它,,,,
//In View DidLoad
UIWindow* currentWindow = [UIApplication sharedApplication].keyWindow;
alert=[[MyAlertView alloc] init];
[alert setAlert:currentWindow];
//Wherever you want to show Alert on your navigation bar.
[alert showAlert:@"Your Message"];