Stu*_*rtM 3 objective-c uiviewcontroller modalviewcontroller presentmodalviewcontroller ios
我通过搜索看到了一些这些问题,但主要与故事板有关.
我只是务实地创建一个模态视图控制器.它实际上是为了使用可达性,一旦连接被视为NotReachable,我提出了一个模态视图控制器,如下所示:
-(void)checkConnection: (Reachability*) curReach {
NetworkStatus netStatus = [curReach currentReachabilityStatus];
if (netStatus == NotReachable) {
NSLog(@"inernet reach - not reachable");
UIViewController *modalViewController = [[MESConnectionModalViewController alloc] init];
modalViewController.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2f];
modalViewController.view.opaque= YES;
[self.window.rootViewController presentModalViewController:modalViewController animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
在视图控制器中MESConnectionModalViewController,目前没有代码,只有标准.
当模态视图转换到当前视图时,背景看起来是正确的(这是短暂的一两秒).一旦模态完全在屏幕上,它就是全黑,而不是部分黑色.我期待基本上略微涵盖当前的内容.上面的代码在应用程序委托中是seutp,每当Reachability更新时调用,所以我试图在解决因特网连接时显示模态视图控制器.
模态视图不支持透明度(适用于iPhone).
但您可以将"UIView"添加到父视图并使用它进行动画处理CoreAnimation
编辑
-(void)checkConnection: (Reachability*) curReach {
NetworkStatus netStatus = [curReach currentReachabilityStatus];
if (netStatus == NotReachable) {
NSLog(@"internet reach - not reachable");
UIViewController *modalViewController = [[MESConnectionModalViewController alloc] init];
//Set y position to animate it
CGRect frame = modalViewController.view.frame;
frame.origin.y = [[UIApplication sharedApplication] keyWindow].frame.size.height;
modalViewController.view.frame = frame;
modalViewController.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2f];
[self.view addSubview:modalViewController.view];
//Animate appearing
frame.origin.y = 0;
[UIView animateWithDuration:0.2 animations:^{
modalViewController.view.frame = frame;
}];
}
}
Run Code Online (Sandbox Code Playgroud)
此外,您可以将其存储modalViewController为属性以便将来访问它.
| 归档时间: |
|
| 查看次数: |
2693 次 |
| 最近记录: |