有时当我懒得用其他库我只是这样做:
// 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];
,然后调用发现这些观点的方法,淡化出来,并删除它们:
-(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];
}
];
}
有时我只想显示一条消息几秒钟,所以我在为navigationController添加覆盖视图后立即打电话给我:
[self performSelector:@selector(removeOverlayViews) withObject:nil afterDelay:4];
它不包含导航栏,因为您需要将子视图添加到self.navigationController.view。有一个视图层次结构,例如1:顶部栏2:导航栏3:选项卡栏4:您的视图 – 2012-08-10 13:17:28