首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动画状态栏iOS 7

动画状态栏iOS 7
EN

Stack Overflow用户
提问于 2013-12-17 06:16:28
回答 1查看 1.7K关注 0票数 3

我试图(挣扎)在iOS7中为我的应用程序实现类似snapchat的错误消息显示(snapchat错误消息滑过状态栏)。我不能为我的生活得到我的动画工作正常。下面是我制作动画的方法

代码语言:javascript
复制
- (void)animateHeaderViewWithText:(NSString *)text {

    //add header views
    [self.headerView addSubview:self.headerLabel];
    [self.navigationController.view addSubview:self.headerView];

    //Hide the Status Bar
    statusBarHidden = TRUE;
    [self setNeedsStatusBarAppearanceUpdate];

    self.headerLabel.text = text;

    [UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{

        self.headerLabel.frame = CGRectMake(0, 0, 320, 20);
        self.headerView.frame = CGRectMake(0, 0, 320, 20);


    } completion:^(BOOL finished) {


    [UIView animateWithDuration:.5 delay:5.0 options:UIViewAnimationOptionCurveEaseIn animations:^{

        //UnHide the Status Bar
        statusBarHidden = FALSE;
        [self setNeedsStatusBarAppearanceUpdate];

        self.headerLabel.frame = CGRectMake(0, -20, 320, 20);
        self.headerView.frame = CGRectMake(0, -20, 320, 20);



    } completion:^(BOOL finished) {


        [self.headerView removeFromSuperview];
        [self.headerLabel removeFromSuperview];

    }];
}];

}

只有动画的后半部分才能正常工作,消息会很好地滑回来,状态栏就会出现在它下面。然而,动画的前半部分,当视图向下滑动时,状态栏消失,导致我的导航栏向上移动,搅乱了我的动画。如何才能让我的导航条停留在最初放置的位置,即使状态栏已经没有了

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-17 07:30:24

此代码在纵向上工作,但需要对其进行修改,以便在这两种方向上正常工作。它使用一个单独的UIWindow作为覆盖,因此不需要隐藏或取消隐藏状态栏。

代码语言:javascript
复制
@interface ViewController ()
@property (strong,nonatomic) UIWindow *dropdown;
@property (strong,nonatomic) UILabel *label;
@property (strong,nonatomic) UIWindow *win;
@end

@implementation ViewController

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.dropdown = [[UIWindow alloc] initWithFrame:CGRectMake(0, -20, 320, 20)];
    self.dropdown.backgroundColor = [UIColor redColor];
    self.label = [[UILabel alloc] initWithFrame:self.dropdown.bounds];
    self.label.textAlignment = NSTextAlignmentCenter;
    self.label.font = [UIFont systemFontOfSize:12];
    self.label.backgroundColor = [UIColor clearColor];
    [self.dropdown addSubview:self.label];
    self.dropdown.windowLevel = UIWindowLevelStatusBar;
    [self.dropdown makeKeyAndVisible];
    [self.dropdown resignKeyWindow];

}

- (IBAction)dropDown:(UIButton *)sender {
    [self animateHeaderViewWithText:@"This is my test string"];
}


-(void)animateHeaderViewWithText:(NSString *) text {
    self.label.text = text;
    CGRect frame = self.dropdown.frame;
    frame.origin.y = 0;
    [UIView animateWithDuration:.6 delay:0 options:0 animations:^{
        self.dropdown.frame = frame;
    }completion:^(BOOL finished) {
        ;
    }];
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20627260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档