Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 窗口幻灯片动画_Ios_Objective C_Animation_Uiwindow - Fatal编程技术网

Ios 窗口幻灯片动画

Ios 窗口幻灯片动画,ios,objective-c,animation,uiwindow,Ios,Objective C,Animation,Uiwindow,我正在显示一个新的UIWindow,我希望它从左侧滑入,并在关闭时滑入左侧。如何设置显示和删除UIWindow的动画 这就是我当前显示新UIWindow的方式 - (void)showMenu { CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screen

我正在显示一个新的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];
    }
也许是这样

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) {

                 }];

可以像任何其他视图一样设置
ui窗口的动画(使用
ui视图
动画方法)

有几件事需要记住您需要保留一个窗口,使其保持在屏幕上。此外,您需要记住,windows在屏幕坐标中运行,而不是在视图坐标中运行,因此在启动动画之前,您需要考虑当前的界面方向

在上面的示例中,我看到您正在创建一个窗口,使其成为关键点并可见。。。还有娜达。你需要保留窗口


此外,您正在错误地使用API。设置根视图控制器后,框架将负责该视图。您再次将其添加为子视图,这可能会把事情搞得一团糟。您确实不应该直接将子视图添加到窗口中,只需将它们添加到视图控制器的视图层次结构中,然后由该层次结构处理即可。

我创建的窗口显示得很好,除了从屏幕左侧设置动画外,它完全可以执行我希望它执行的操作。在您的代码中,没有动画。张贴动画代码,以便我可以查看。动画是我不确定如何实际操作的。在使窗口可见之前,请将其帧设置为初始帧,然后将其设置为可见,然后使用
animateWithDuration:animations:
设置帧。这真的很简单。你不正确地使用了API。设置根视图控制器后,框架将负责该视图。您再次将其添加为子视图,这可能会把事情搞得一团糟。您确实不应该直接将子视图添加到窗口中,只需将它们添加到视图控制器的视图层次结构中,然后由它来处理。