【发布时间】:2023-03-06 21:37:01
【问题描述】:
我要使用 Facebook 式的滑动 UITableView。
我已经做到了,动画和阴影等等。我担心的是我的做法完全错误,然后事情就不会完全正确。
应用程序有一个(UIWindow 的)rootViewController,它是一个 UINavigationController。 UINavigationController(其根视图控制器)内的视图设置了 leftBarButtonItem 属性。这是按下按钮时运行的代码。
- (void)showFeedList {
//set the feed list as showing even before it is
feedListShowing = YES;
//to show the feed list, we need to instanciate one
feedSelectionListViewController = [[FeedSelectionListViewController alloc] initWithNibName: @"FeedSelectionListViewController" bundle: nil];
//set the frame to 200 points to the left of the screen
feedSelectionListViewController.view.frame = CGRectOffset(feedSelectionListViewController.view.frame, -200, 20);
NSInteger offset = feedSelectionListViewController.view.frame.size.width;
//store a pointer to the root navigation controller, and add the list view controller's view to the navigation controller's view
UINavigationController *navigationController = (UINavigationController *)UIApplication.sharedApplication.delegate.window.rootViewController;
[navigationController.view addSubview: feedSelectionListViewController.view];
//animate the navigation bar, feed selection list, and this view controller's view to the right
[UIView animateWithDuration: LIST_SHOW_TRANSITION_TIME animations: ^{
self.view.frame = CGRectOffset(self.view.frame, offset, 0);
navigationController.navigationBar.frame = CGRectOffset(navigationController.navigationBar.frame, offset, 0);
feedSelectionListViewController.view.frame = CGRectOffset(feedSelectionListViewController.view.frame, offset, 0);
}];
}
这真的很混乱,而且并不是所有的东西都能正常工作。首先,当用户离开并返回应用程序时,UINavigationBar 似乎已经重置了它的框架。当通话状态栏打开和关闭时也会发生这种情况。其次,右侧视图内的任何视图都不会按应有的方式向右移动。我不知道这是为什么。
但是,如果我将动画块替换为
navigationController.view.frame = CGRectOffset(navigationController.view.frame, 200, 0);
它工作正常。导航控制器当前显示的视图的子视图相应地移动,当应用程序恢复时,一切都在正确的位置。但是,侧边栏视图没有接收触摸事件,在侧边栏上进行的触摸现在由 AppDelegate 处理。我怀疑这是因为 UIView 的框架的原点是 {-200, 0},但我不能确定。
我不认为我理解了什么。这甚至是正确的方法吗?我想不出任何其他方法来做到这一点。无论如何,非常感谢您提供任何指导或建议。
-马特
【问题讨论】:
标签: ios uiview uinavigationcontroller uikit