Tôi có chế độ xem có nhiều văn bản trong đó, vì vậy tôi muốn cho phép người dùng ẩn trạng tháiBar + navigationBar trên một lần nhấn. Tôi thực sự thích phong cách ẩn trong ứng dụng Ảnh, trong đó statusBar và navigationBar ẩn với nhau (không trượt, chỉ mờ dần), với một số animationDuration, vì vậy tôi đã cố gắng làm một việc như thế. Đây là những gì tôi làm trong phương pháp touchesDidBegan:ẩn thanh trạng thái và thanh điều hướng đồng thời, như trong ứng dụng Ảnh
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
[UIView setAnimationDuration:0.5];
[UIView beginAnimations:@"" context:nil];
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:UIStatusBarAnimationNone];
[self.navigationController setNavigationBarHidden:(!self.navigationController.navigationBarHidden) animated:NO];
[UIView commitAnimations];
self.navigationController.navigationBar.translucent = !self.navigationController.navigationBar.translucent; // this is needed to make bars appear on top of my view.
}
Nhưng điều này không đồng thời ẩn các quán bar. Nó làm cho chúng trượt xuống. Nó có tác dụng tương tự như phiên bản này của phương pháp trên:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
// deleted UIView animation, changed animation type to "slide"
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:UIStatusBarAnimationSlide];
// enabled animation for navBar
[self.navigationController setNavigationBarHidden:(!self.navigationController.navigationBarHidden) animated:YES];
self.navigationController.navigationBar.translucent = !self.navigationController.navigationBar.translucent; // this is needed to make bars appear on top of my view.
}
Nếu tôi loại bỏ hoạt ảnh UIView và ẩn các thanh không có hoạt ảnh, chúng ẩn và xuất hiện đồng thời, nhưng quá nhanh. Có lẽ tôi đang đi sai hướng. Sẽ đánh giá cao nếu ai đó có thể giúp tôi với điều này.
Edit: đã nhận nó làm việc
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// don't forget to set navigationBar.translucent to YES
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
[UINavigationBar setAnimationDuration:3.0];
[UINavigationBar beginAnimations:@"" context:nil];
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:NO];
if ([UIApplication sharedApplication].isStatusBarHidden)
[self.navigationController.navigationBar setAlpha:0.0];
else [self.navigationController.navigationBar setAlpha:1.0];
[UINavigationBar commitAnimations];
}
Tôi nhìn qua src của họ và tìm thấy ẩn/hiện ra phương pháp xử lý trong src/KTPhotoBrowser/KTPhotoScrollViewController.m họ cũng quấn trên thanh trạng thái và thanh điều hướng trốn vào UIView hoạt hình.Tuy nhiên, thay vì đặt navigationBarHidden thành YES, chúng chỉ thay đổi giá trị alpha của navigationBar từ 1.0 đến 0.0. Chỉ cần giữ navigationBar.transulent = YES. Tôi đoán setNavigationBarHidden: hoạt hình: phương pháp cho phép hoạt hình riêng của mình khi được đưa vào hoạt ảnh UIView (gây ra asynchronicity bw statusbar và navigationBar). Cảm ơn mặc dù. – AzaFromKaza
cũng làm bạn của tôi, và bạn cũng đến! –