Ios7 如何在iOS 7上淡出状态栏和导航栏,如Photos.app

Ios7 如何在iOS 7上淡出状态栏和导航栏,如Photos.app,ios7,hidden,statusbar,navigationbar,Ios7,Hidden,Statusbar,Navigationbar,基本上,这是一个非常简单的需求,但我尝试了几种方法,但都没有达到预期效果。最接近的功能片段是: #import "ViewController.h" @implementation ViewController - (void)dealloc { [scrollView release]; scrollView = nil; [super dealloc]; } - (id)init { if (self = [super init]) {

基本上,这是一个非常简单的需求,但我尝试了几种方法,但都没有达到预期效果。最接近的功能片段是:

#import "ViewController.h"

@implementation ViewController

- (void)dealloc
{
    [scrollView release];
    scrollView = nil;

    [super dealloc];
}

- (id)init
{
    if (self = [super init])
    {
        self.title = @"Pictures";

        scrollView = [[UIScrollView alloc] init];
        scrollView.delegate = self;
        scrollView.frame = CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
        scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 10, scrollView.bounds.size.height);
        scrollView.showsVerticalScrollIndicator = NO;
        scrollView.showsHorizontalScrollIndicator = NO;
        scrollView.pagingEnabled = YES;
        scrollView.userInteractionEnabled = YES;
        scrollView.backgroundColor = [UIColor blackColor];
        self.wantsFullScreenLayout = YES;
        self.automaticallyAdjustsScrollViewInsets = NO;
        isHidden = NO;
    }
    return self;
}

- (void)viewDidLoad
{
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [scrollView addGestureRecognizer:tapGesture];
    [tapGesture setNumberOfTapsRequired:1];
    [tapGesture release];

    for (int i = 0; i < 10; i++)
    {
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/path/to/%d.png", i + 1]];
        UIImageView *imageView= [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width * i, 0.0f, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.image = image;
        [scrollView addSubview:imageView];
        [image release];
        [imageView release];
    }

    [self.view addSubview:scrollView];
}

- (void)tap:(UITapGestureRecognizer *)gesture
{
    [UINavigationBar setAnimationDuration:1.0];
    [UINavigationBar beginAnimations:@"HideTopBars" context:nil];

    isHidden = !isHidden;
    // [self setNeedsStatusBarAppearanceUpdate];

    self.navigationController.navigationBar.alpha = isHidden ? 0.0f : 1.0f;
    [UINavigationBar commitAnimations];
}

- (void)scrollViewDidScroll:(UIScrollView *)view
{
    // further operation
}

- (BOOL)prefersStatusBarHidden
{
    return isHidden;
}
@end
#导入“ViewController.h”
@实现视图控制器
-(无效)解除锁定
{
[滚动视图发布];
scrollView=nil;
[super dealoc];
}
-(id)init
{
if(self=[super init])
{
self.title=@“图片”;
scrollView=[[UIScrollView alloc]init];
scrollView.delegate=self;
scrollView.frame=CGRectMake(0.0f,0.0f,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height);
scrollView.contentSize=CGSizeMake([UIScreen mainScreen].bounds.size.width*10,scrollView.bounds.size.height);
scrollView.showsVerticalScrollIndicator=否;
scrollView.showsHorizontalScrollIndicator=否;
scrollView.PaginEnabled=是;
scrollView.userInteractionEnabled=是;
scrollView.backgroundColor=[UIColor blackColor];
self.wantsFullScreenLayout=是;
self.automaticallyAdjustsScrollViewInsets=否;
isHidden=否;
}
回归自我;
}
-(无效)viewDidLoad
{
UITapGestureRecognizer*点击手势=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(点击:)];
[滚动视图添加手势识别器:点击手势];
[TAPPORATE setNumberOfTapsRequired:1];
[手势释放];
对于(int i=0;i<10;i++)
{
UIImage*image=[[UIImage alloc]initWithContentsOfFile:[NSString stringWithFormat:@”/path/to/%d.png“,i+1]];
UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width*i,0.0f,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height];
imageView.contentMode=UIViewContentModeScaleAspectFit;
imageView.image=图像;
[滚动视图添加子视图:图像视图];
[图片发布];
[图像视图发布];
}
[self.view addSubview:scrollView];
}
-(无效)轻触:(UITapgestureRecognitor*)手势
{
[UINavigationBar设置动画持续时间:1.0];
[UINavigationBar开始激活:@“HideTopBars”上下文:无];
isHidden=!isHidden;
//[self-setNeedsStatusBarAppearanceUpdate];
self.navigationController.navigationBar.alpha=ishiden?0.0f:1.0f;
[UINavigationBar委员会];
}
-(无效)scrollViewDidScroll:(UIScrollView*)视图
{
//进一步操作
}
-(BOOL)更喜欢StatusBarHidden
{
返回伊希登;
}
@结束

如果没有“[self-setNeedsStatusBarAppearanceUpdate]”,导航栏确实会按预期褪色,但状态栏上的文本仍然可见,我猜这是因为状态栏将导航栏作为背景图像,而状态栏本身不会褪色;使用“[self-setNeedsStatusBarAppearanceUpdate]”,文本也会淡出,但导航栏的动画会随着淡出效果从屏幕顶部滑入/滑出。我还尝试将“[self-setNeedsStatusBarAppearanceUpdate]”移动到prefersStatusBarHidden,但这只是让导航栏永远可见。我相信这不是一个奇怪的需求,所以我打赌有更好更简单的解决方案。有什么想法吗?

请查看我对类似问题的解决方案: