gpt4 book ai didi

ios - 动画状态栏 iOS 7

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:21 24 4
gpt4 key购买 nike

我正在尝试(努力)在 iOS7 中为我的应用程序实现类似 snapchat 的错误消息显示(snapchat 错误消息以某种方式在状态栏上向下滑动)。我一辈子都无法让我的动画正常工作。这是我制作动画的方法

- (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];

}];
}];

}

只有动画的后半部分才能正常工作,消息可以很好地向上滑动,状态栏出现在它下面。然而,动画的前半部分,当 View 向下滑动时,状态栏消失导致我的导航栏向上移动,搞砸了我的动画。我怎样才能让我的导航栏留在它最初放置的位置,即使状态栏消失了

最佳答案

此代码可在纵向模式下使用,但需要进行修改才能在两个方向上正常工作。它使用单独的 UIWindow 作为叠加层,因此无需隐藏或取消隐藏状态栏。

@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) {
;
}];
}

关于ios - 动画状态栏 iOS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20627260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com