【发布时间】:2014-06-10 22:19:28
【问题描述】:
在我的 iOS 应用程序中,我展示了一个视图控制器,其 modalTransitionStyle = UIModalTransitionStyleFlipHorizontal。当控制器出现时,其工具栏中的文本 UIBarButtonItem 会在控制器翻转到位时执行奇怪的幻灯片动画。
我不希望这个动画发生。如何预防?
编辑:感谢 Swift 的简洁性,这里有一个重现问题的完整示例:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.makeKeyAndVisible()
let vc = TestVC()
self.window!.rootViewController = UINavigationController(rootViewController: vc)
return true
}
}
class PresentedVC: UIViewController {
init() {
super.init(nibName: nil, bundle: nil)
toolbarItems = [UIBarButtonItem(title: "Foo", style: .Plain, target: nil, action: nil)]
modalTransitionStyle = .FlipHorizontal
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController!.setToolbarHidden(false, animated: false)
}
}
class TestVC: UITableViewController {
override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = UITableViewCell(style: .Default, reuseIdentifier: "noId")
cell.textLabel.text = "Foo"
return cell
}
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
let vc = PresentedVC()
let nvc = UINavigationController(rootViewController: vc)
self.presentViewController(nvc, animated: true, completion: nil)
}
}
【问题讨论】:
-
为什么需要将navigationBar.hidden设置为FALSE?默认不是false吗?
-
不,默认是这样的。
-
是的,我在考虑导航栏,而您正在使用工具栏。我没有在 viewWillAppear 中将 setToolbarHidden 设置为 False,而是尝试在 TestVC 的 didSelectRowAtIndexPath 方法中将其设置为 false。它在这里工作,动画是正常的。这对你有用吗?
标签: ios cocoa-touch animation swift uitoolbar