đôi khi tôi lười biếng để sử dụng các thư viện khác tôi chỉ làm điều này:
// create a custom black view
UIView *overlayView = [[UIView alloc] initWithFrame:self.navigationController.view.frame];
overlayView.backgroundColor = [UIColor blackColor];
overlayView.alpha = 0.8;
overlayView.tag = 88;
// create a label
UILabel *message = [[UILabel alloc] initWithFrame:self.navigationController.view.frame];
[message setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:25.0f]];
message.text = @"message to my dear user";
message.textColor = [UIColor whiteColor];
message.textAlignment = NSTextAlignmentCenter;
message.tag = 99;
// and just add them to navigationbar view
[self.navigationController.view addSubview:overlayView];
[self.navigationController.view addSubview:message];
và sau đó gọi một phương pháp mà tìm thấy những quan điểm, mất dần chúng ra và xóa chúng:
-(void) removeOverlayViews{
UIView *view = (UIView *)[self.navigationController.view viewWithTag:88];
UILabel *label = (UILabel *)[self.navigationController.view viewWithTag:99];
[UIView animateWithDuration:0.5
animations:^{
view.alpha = 0.0;
label.alpha = 0.0;
}
completion:^(BOOL finished){
[view removeFromSuperview];
[label removeFromSuperview];
}
];
}
đôi khi tôi chỉ muốn hiển thị thông báo trong vài giây nên tôi gọi ngay sau khi tôi thêm chế độ xem lớp phủ vào điều hướngController:
[self performSelector:@selector(removeOverlayViews) withObject:nil afterDelay:4];
Nó không bao gồm navbar vì bạn cần phải thêm subview vào self.navigationController.view. Có một hệ thống phân cấp các khung nhìn, nói 1: thanh trên cùng 2: thanh điều hướng 3: thanh tab 4: chế độ xem của bạn –