dea*_*_au 8 animation cocoa-touch uinavigationcontroller titleview
我可能在这里做错了,因为这看起来有点愚蠢.
我在我的UINavigationController上设置了一个自定义titleView(以UILabel的形式),在每个页面上都是相同的.为了实现这一点,我在我的app delegate中创建了一个函数来正确显示标签.然后我将其推送到导航堆栈后,在任何子视图上调用此函数.
这是代码(可能比我的解释更有意义):
//In MyAppDelegate.m:
- (void)showTitleForNavigationController:(UINavigationController*) navController {
UILabel *label = [[UILabel alloc] init];
// set up label attributes
// ...
[label sizeToFit]; //without this line my label won't show at all
[navController.navigationBar.topItem setTitleView:label];
[label release];
}
// In SomeViewController.m, when pushing another controller onto the stack:
UIViewController *otherViewController = //initialize other view controller;
[self.navigationController pushViewController:otherViewController animated:YES];
[(MyAppDelegate*)[[UIApplication sharedApplication] delegate] showTitleForNavigationController:otherViewController.navigationController];
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我将下一个视图控制器推入堆栈,并且新控制器平滑地滑动时,在动画的整个持续时间内,标签粘贴在左上方,然后在动画结束后最终捕捉到位.它看起来很奇怪和丑陋.如何正确设置标签,使其从下一个视图平滑滑动?当然,这很简单,我很想念......
| 归档时间: |
|
| 查看次数: |
8546 次 |
| 最近记录: |