Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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从另一个视图的一侧滑动UIView(菜单)_Ios_Cocoa Touch_Uiview_Ios4_Core Animation - Fatal编程技术网

iOS从另一个视图的一侧滑动UIView(菜单)

iOS从另一个视图的一侧滑动UIView(菜单),ios,cocoa-touch,uiview,ios4,core-animation,Ios,Cocoa Touch,Uiview,Ios4,Core Animation,我想在按钮单击事件后从视图的一侧滑入菜单。在另一个按钮点击后,菜单应该从大视图中滑出 我尝试过CATTransition,但我无法解决这个问题 CATransition *animation = [CATransition animation]; [animation setDuration:1]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromBottom]; [animation s

我想在按钮单击事件后从视图的一侧滑入菜单。在另一个按钮点击后,菜单应该从大视图中滑出

我尝试过CATTransition,但我无法解决这个问题

CATransition *animation = [CATransition animation];
[animation setDuration:1];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]] ;

[[menuView layer] addAnimation:animation forKey:@"@asdf"];        
[menuView setCenter:CGPointMake([menuView center].x, [menuView center].y + 450)];
这有点奏效,但我不明白为什么-/

像这样的控制器将使您能够做到这一点

编辑: 我不知道还有什么要补充的,主持人。这是一个开源代码,它将添加一个由按钮控制的菜单,该按钮在单击时滑入,再次单击时滑出,类似于Facebook和Path的功能。您还可以通过幻灯片获得触摸事件


这里有一个如何在github页面上使用它的示例:还有几个源代码中提供的示例项目。

如果您想自己实现它,您可以使用一种方法,即创建自定义视图并为视图控制器中的按钮添加按钮单击事件

还可以创建一个布尔变量来标识自定义视图是否可见

单击时,如果菜单视图不可见,则执行以下操作:

-(void)viewDidLoad
{
    ...

    // ---------------------------------------------
    // create the custom menu view off screen
    // ---------------------------------------------
    menuView = [[MenuView alloc] initWithFrame:CGRectMake(-320, 0, 320, 480)];
    menuView.alpha = 0; // hide it so it doesn't show at the start, only show when slide in

    [self.view addSubview:menuView];

    ...
}

-(void)toggleMenu
{
    if(menuIsVisible)
    {
        menuIsVisible = NO;

        [self hideMenu];
    }
    else
    {
        menuIsVisible = YES;

        [self showMenu];
    }
}

-(void)hideMenu
{
    [UIView animateWithDuration:0.5 animations:^{
        // note CGAffineTransforms doesn't use coordinates, they use offset
        // so an offset of (0,0) would bring the menuView back to the coordinate
        // when it was first instantiated, in our case, (-320, 0).
        menuView.transform = CGAffineTransformMakeTranslation(0,0);
    } completion:^{
        // hide the menu
        menuView.alpha = 0;
    }];
}

-(void)showMenu
{
    // show the menu
    menuView.alpha = 1;

    [UIView animateWithDuration:0.5 animations:^{
        // note CGAffineTransforms doesn't use coordinates, they use offset
        // so an offset of (320,0) from coordinate (-320,0) would slide the
        // menuView out into view
        menuView.transform = CGAffineTransformMakeTranslation(320,0);
    }];
}

你应该把你已经尝试过的东西贴出来。你说的“有点用”是什么意思?它做了什么,和你想要的有什么不同?好的,“菜单”是滑入的-这是正确的,但有一个阿尔法混合效果,我不明白…建议的代码将如何帮助?请扩展您的答案,使其不仅仅是一个链接,否则可能会被删除。