我正在尝试模仿facebook ios侧面菜单并使它正常工作,但是我遇到的问题是,我无法像在iphone facebook side menu using objective c上另一个问题中所讨论的那样将侧面菜单发送到背面。我没有使用建议的库,而是使用了建议的代码。我有

- (void)viewDidLoad
{
    NSLog(@"View Did Load is running");
    activitySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activitySpinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
    activitySpinner.center = self.view.center;
    [self.view addSubview:activitySpinner];

    SideMenuView *myDelegate = [[SideMenuView alloc] init];
    [self setSideMenuDelegate:myDelegate];
    //set the delegate's currentViewController property so that we can add a subview to this View.
    [sideMenuDelegate setCurrentViewController:self];

    //sideMenu = [[SideMenuView alloc] initWithNibName:@"SideMenuView" bundle:nil];
    [self.view addSubview:myDelegate.view];
    [self.view sendSubviewToBack:myDelegate.view];

    [super viewDidLoad];
    self.searchDisplayController.searchBar.scopeButtonTitles = nil;

    [self fetchCustomers];
    // Do any additional setup after loading the view, typically from a nib.
}

在 Controller 中,我需要侧面菜单,但 View 似乎已加载到当前 View 中,而不仅仅是后退,因此在将菜单滑过时可以看到它。

有人可以帮我把myDelegate View 放到后面吗?

最佳答案

我不确定您要完成什么,所以我不得不猜测。听起来您想将myDelegate.view隐藏在self.view后面。这样行不通。
sendSubviewToBack:将 subview 发送到发送者的 View 层次结构的后面(在您的情况下为self.view)。它永远不会在其父 View 下方发送 subview 。

您可以改为将myDelegate.view作为 subview 添加到self.view的 super View 中,并将其放在self.view后面:

[[self.view superview] insertSubview:myDelegate.view belowSubview:self.view];

09-25 18:45
查看更多