【发布时间】:2016-10-23 21:00:05
【问题描述】:
我正在尝试从 Tinder 重新创建导航行为。为此,我已将 Framework delivering the NavigationBar 翻译成 Swift 3。
测试应用程序非常简单。我已经创建了一个测试git project,如果有人感兴趣的话。
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var controller: SLPagingViewSwift!
var nav: UINavigationController?
var home: ViewController?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let orange = UIColor(red: 255/255, green: 69.0/255, blue: 0.0/255, alpha: 1.0)
let gray = UIColor(red: 0.84, green: 0.84, blue: 0.84, alpha: 1.0)
let stb = UIStoryboard(name: "Main", bundle: nil)
self.home = stb.instantiateViewController(withIdentifier: "ViewController") as? ViewController
let vc2 = ViewController()
vc2.view.backgroundColor = .red
let vc3 = ViewController()
vc3.view.backgroundColor = .blue
var homeBtn = UIImage(named: "profile")
homeBtn = homeBtn?.withRenderingMode(.alwaysTemplate)
var vc2Btn = UIImage(named: "gear")
vc2Btn = vc2Btn?.withRenderingMode(.alwaysTemplate)
var vc3Btn = UIImage(named: "chat")
vc3Btn = vc3Btn?.withRenderingMode(.alwaysTemplate)
let items = [UIImageView(image: homeBtn),
UIImageView(image: vc2Btn),
UIImageView(image: vc3Btn)]
let controllers = [self.home!,
vc2,
vc3] as [UIViewController]
self.controller = SLPagingViewSwift(items: items, controllers: controllers, showPageControl: false)
self.controller.pagingViewMoving = ({ subviews in
if let imageViews = subviews as? [UIImageView] {
for imgView in imageViews {
var c = gray
let originX = Double(imgView.frame.origin.x)
if (originX > 45 && originX < 145) {
c = self.gradient(originX, topX: 46, bottomX: 144, initC: orange, goal: gray)
}
else if (originX > 145 && originX < 245) {
c = self.gradient(originX, topX: 146, bottomX: 244, initC: gray, goal: orange)
}
else if(originX == 145){
c = orange
}
imgView.tintColor = c
}
}
})
self.nav = UINavigationController(rootViewController: self.controller)
self.window?.rootViewController = self.nav
self.window?.backgroundColor = UIColor.black
self.window?.makeKeyAndVisible()
return true
}
在我的UIViewController 中,我希望在单击单元格后将一个新的UIViewController 推入UINavigationController 堆栈(具有后退按钮和后退按钮)。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let stb = UIStoryboard(name: "Main", bundle: nil)
let vc = stb.instantiateViewController(withIdentifier: "SegueVC")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.controller?.navigationController?.pushViewController(vc, animated: true)
//appDelegate.nav?.pushViewController(vc, animated: true)
}
问题是,SegueVC 与根具有相同的UINavigationBar。
基本上我希望SegueVC 的UINavigationBar 与根控制器的栏重叠以具有此:
如果我将 SegueVC 推到 controller 或 nav 上没有任何区别。
appDelegate.controller?.navigationController?.pushViewController(vc, animated: true)
//appDelegate.nav?.pushViewController(vc, animated: true)
如AppDelegate所示的结构:nav是window的rootViewController和var controller: SLPagingViewSwift!的UINavigationController。
self.nav = UINavigationController(rootViewController: self.controller)
self.window?.rootViewController = self.nav
self.window?.backgroundColor = UIColor.black
self.window?.makeKeyAndVisible()
我正在考虑在导航堆栈之外呈现 SegueVC 动画,但后来我错过了内置的后退按钮和滑动后退手势。我有哪些选择?非常感谢您的帮助。
【问题讨论】:
-
你可以通过为你的 mainVC 设置一个容器并相应地移动它来做到这一点......我相信 twitter 动画很容易实现......我在我的项目中使用相同类型的动画转换。看起来很酷……干杯
-
所以。我的 mainVC 上有一个容器并为其可见性设置动画?
-
这就是所有 sideMenuView 的工作方式。我强烈建议在 giithub github.com/evnaz/ENSwiftSideMenu 检查这个项目,并检查我的答案 stackoverflow.com/questions/40059328/…
-
非常感谢您的意见!随意回答,我肯定会赞成
-
如果您想从您的帖子中获得您的第一个截屏视频。我相信您可以轻松隐藏您的状态栏和导航栏。并在导航栏位置放置一个 UIView 顶部检查我的答案stackoverflow.com/questions/40176803/… 并放置一个 uiview lager 然后 storyBoard 像 view.frame.width + 100 (无论大小适合你)并使用 UIView (你可以使用容器来) 检测到 swipeGesture 时的偏移位置...我希望您尽快完成此操作...干杯