预览过渡-更新 2.1.4

预览过渡-更新 2.1.4

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2018年10月
SPM支持SPM

Guillaume Bellut维护。



  • 作者
  • Juri Vasylenko和Guillaume Bellut

header

Preview-transition

Twitter
Travis
Carthage compatible
CocoaPods
CocoaPods
CocoaPods
codebeat badge

关于

此项目由Ramotion,Inc.维护。

我们专门从事移动应用和网站的定制UI设计和编码。

寻找您的项目的开发者吗?

StackViewController Example App

您可在此找到iPhone mockup

在实践中尝试这个UI控件

需求

  • iOS 9.0+
  • Xcode 8

许可证

Preview-transition是基于MIT许可证发布的。
有关详情,请参阅LICENSE

安装

只需将源文件夹添加到您的项目中,或者像这样使用CocoaPods

pod "PreviewTransition", "~> 2.0.1" swift 3

pod "PreviewTransition", "~> 1.1.5" swift 2

或对Carthage用户,只需简单地将它添加到他们的Cartfile

github "Ramotion/preview-transition"

使用

  1. import PreviewTransition

  2. 创建继承自PTTableViewController的UITableViewController子类

  3. 添加UITableViewDelegate方法

public override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return <RowsCount>
}

public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    return tableView.dequeueReusableCellWithIdentifier(<CellIdentifier>, forIndexPath: indexPath)
}
  1. 添加一个ParallaxCell

storyboards
创建一个继承自ParallaxCell的cell;不要忘记设置identifier <CellIdentifier>

或以编程方式
在viewDidLoad中注册cell tableView.registerClass(ParallaxCell, forCellReuseIdentifier:<CellIdentifier>)

  1. 设置cell高度

  2. 创建图像名称(图像尺寸必须等于屏幕尺寸或更大)

let images = [image_name, image_name, image_name, image_name, image_name] // image names
  1. 为ParallaxCell设置图像和文本
public override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    guard let cell = cell as? ParallaxCell else {
      return
    }

    let imageName = images[indexPath.row]

    if let image = UIImage(named: imageName) {
      cell.setImage(image, title: <SetText>)
    }
}

您的tableViewController应该看起来像DemoTableViewController

我们将稍后添加的方法 public override func tableView(tableView: didSelectRowAtIndexPath indexPath:)。(第10步)

  1. 创建继承自PTDetailViewController的UIViewController

  2. 为backButton添加动作并调用popViewController()

func backButtonHandler() {
    popViewController()
}
  1. 在UITableViewController中推送此UIViewController。添加方法
public override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

  // create viewController
  let <YourViewController> = storyboard?.instantiateViewControllerWithIdentifier(<identifier>)
  if case let viewController as <YourViewController> = viewController {
     pushViewController(viewController)
  }
}
  1. 配置UINavigationBar
// transparent background
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().translucent = true
UINavigationBar.appearance().tintColor = .whiteColor()

// set font
if let font = UIFont(name: <Font name> , size: 18) {
      UINavigationBar.appearance().titleTextAttributes = [
        NSForegroundColorAttributeName : UIColor.whiteColor(),
        NSFontAttributeName : font
      ]
}

关注我们

Twitter URL
Twitter Follow