ios - 如何使用动画在 UINavigationBar 上切换 View ?

标签 ios uinavigationbar

我的应用程序中有导航栏

如下图所示

enter image description here

我想要View从上边覆盖完整的UINavigationBar,可以是UIView。然后再次超越动画。

最佳答案

您应该继承 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"];

关于ios - 如何使用动画在 UINavigationBar 上切换 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23402349/

相关文章:

iphone - 使 UINavigationBar 半透明

javascript - 如何在 javascript 中查询 iTunes 搜索 API?

iOS - AdHoc 构建确认

ios - Swift - 更改范围栏色调颜色

iphone - 创建一个自定义 View 来替换 UINavigationBar

ios - swift 4 : Navigation Bar looks different for the next page

ios - 解码包含 boolean 值的枚举

ios - CMSampleBuffer 中有多少帧?

iphone - UINavigationBar 标题在使用自定义字体时被截断

iphone - UIBarButtonItem 突出显示颜色