0

我正在尝试从主 UIButton 后面推出按钮菜单(包含 UIButtons 的 UIView)

我已经包含了一个图像链接,以便更好地了解我所得到的内容(当按下主按钮时,包含按钮的蓝色部分从主按钮后面滑出) -

http://imageshack.us/photo/my-images/27/screenshot20111027at419.png/

我创建了我的 UIView 并将我的按钮放在它上面,它的动画没有任何问题。我的计划是将按钮放在“屏幕外”(相对于我的 UIView 的坐标系),然后对其进行动画处理,以便 UIView 滑动到位(就像一个抽屉柜,UIView 最初是完全隐藏的)

但是按钮出现在原始 UIButton 上,这不是我想要的;)

有什么建议吗?有什么方法可以在主视图的某些部分隐藏 UIView 吗?

很抱歉我的问题冗长,但我是新手:) 非常感谢任何帮助!

时间*

4

3 回答 3

2

@八度音1

我无法对您的问题发表评论,但认为如果您模拟正在发生的事情与您想看到的内容的图像会有所帮助。

或者,您的一些代码将帮助我们解决问题。

在将菜单设置为动画时,您可以隐藏不想看到的视图。这是一个例子(对不起,如果我把你的观点搞混了)

/*
 assume buttonMenu is defined
 assume showMenuButton is defined
 assume menuEndFrame is defined 
*/
[UIView beginAnimations:@"ButtonMenu" context:nil];

[UIView setAnimationDuration:0.25];

buttonMenu.frame = menuEndFrame
showMenuButton.alpha = 0.0

[UIView commitAnimations];

如果这不是问题并且您的视图层次结构是问题,那么您可以使用这两种方法来帮助分层

- (void)bringSubviewToFront:(UIView *)view

- (void)sendSubviewToBack:(UIView *)view
于 2011-10-27T15:17:12.057 回答
2

感谢您提供有用的建议,最终问题出在视图层次结构上,这被证明是有用的:

- (void)sendSubviewToBack:(UIView *)view   

为了更清楚我想要实现的目标,我包含了一个视频来演示(注意我需要使用另一个视图来坐在我的主菜单按钮后面,以便滑动菜单在菜单按钮后面不部分可见,这是深灰色下半部分视图。我使用较深的灰色阴影来显示此视图的位置)

http://www.youtube.com/watch?v=nllXGh9sSls

这是我的一些代码,适用于可能有类似问题的任何人:

- (void) setupInterface {
//setting up the main button & the sliding button menu
[self addMyButton];
buttonMenu = [[ButtonMenu alloc] initWithFrame:(CGRectMake(100, 310, 120, 200)) ];
[self.view addSubview:buttonMenu];
[self.view sendSubviewToBack:buttonMenu];

}


- (void)MenuButtonClicked:(id)sender
{
    [self rollOutIn]; //Call Flip BOOL

if (!rollOutMenuButton)
{
//pushing out the menu  
buttonMenu.alpha = 0.0f;            
[UIView beginAnimations:@"MoveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.8f];
self.buttonMenu.frame = CGRectMake(100, 110, 120, 200);
buttonMenu.alpha = 1.0f;
[UIView commitAnimations];  
}

else 
{
    //pulling the menu back in
    [UIView beginAnimations:@"MoveView" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:0.8f];
    self.buttonMenu.frame = CGRectMake(100, 310, 120, 200);
    buttonMenu.alpha = 0.0f;
    [UIView commitAnimations];
}
}

希望这对其他人有所帮助:)

于 2011-11-10T19:15:20.307 回答
1

这正是 UIPopOverController 旨在解决的用例。我建议您尝试重新发明轮子。

这是来自 Ray Wenderlich 的关于 UIPopOverController 的优秀教程:
http ://www.raywenderlich.com/1056/ipad-for-iphone-developers-101-uipopovercontroller-tutorial

编辑:根据评论和标签,这是关于 iPhone 的问题,而不是 iPad。UIPopOverController 仅适用于 iPad,但有几个第三方库可以为手机带来类似的功能。

这是一个:http: //iosdevelopertips.com/open-source/ios-open-source-popover-api-for-iphone-wepopover.html

没用过,不推荐,不过好像有粉丝。谷歌搜索“popover for iphone”将为您提供一些教程和建议。

于 2011-10-27T15:27:32.100 回答