rag*_*oat 1 animation objective-c uiwindow ios
我正在显示一个新的UIWindow,并且希望它从左侧滑入并在关闭时滑入左侧。如何设置UIWindow的显示和移除动画效果?
这是我当前显示新UIWindow的方式。
- (void)showMenu
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
UIButton *closeMenuButton = [UIButton buttonWithType:UIButtonTypeCustom];
[closeMenuButton setFrame:CGRectMake(250, 10, 50, 50)];
[closeMenuButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
[closeMenuButton addTarget:self action:@selector(closeMenu) forControlEvents:UIControlEventTouchUpInside];
blurredView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
[blurredView setBarStyle:UIBarStyleBlack];
MenuTableViewController *menu = [[MenuTableViewController alloc]initWithNibName:@"MenuTableViewController" bundle:nil];
menu.view.frame = CGRectMake(0, 30, screenWidth, screenHeight - 50);
menuWindow = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
menuWindow.backgroundColor = [UIColor clearColor];
menuWindow.windowLevel = UIWindowLevelStatusBar;
menuWindow.rootViewController = menu;
[menuWindow addSubview:blurredView];
[blurredView addSubview:closeMenuButton];
[blurredView addSubview:menu.view];
[menuWindow makeKeyAndVisible];
}
Run Code Online (Sandbox Code Playgroud)
也许是这样吗?
menuWindow = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, 0, screenHeight)];
menuWindow.backgroundColor = [UIColor clearColor];
menuWindow.windowLevel = UIWindowLevelStatusBar;
menuWindow.rootViewController = menu;
[menuWindow addSubview:blurredView];
[blurredView addSubview:closeMenuButton];
[blurredView addSubview:menu.view];
[menuWindow makeKeyAndVisible];
[UIView animateWithDuration:0.5 animations:^{
menuWindow.frame = screenRect;
blurredView.frame = screenRect;
menu.view.frame = CGRectMake(0, 30, screenWidth, screenHeight - 50);
}
completion:^(BOOL finished) {
}];
Run Code Online (Sandbox Code Playgroud)
您可以UIWindow像其他任何视图一样使用UIView动画(使用动画方法)。
需要记住的几件事。您需要保留一个窗口以使其保留在屏幕上。另外,您需要记住,窗口位于屏幕坐标中,而不位于视图坐标中,因此在开始动画之前,您需要考虑当前的界面方向。
在上面的示例中,我看到您正在创建一个窗口,使其成为键并可见...以及nada。您需要保留窗口。
另外,您使用的API错误。设置根视图控制器后,框架将负责该视图。再次将其添加为子视图,这可能会造成混乱。您确实不应该将子视图直接添加到窗口中,而应该将它们添加到视图控制器的视图层次结构中,然后由其处理。
| 归档时间: |
|
| 查看次数: |
2936 次 |
| 最近记录: |