All Projects → toannt → Pvview

toannt / Pvview

Licence: mit
A small library that helps you to make an amazing parallax view

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Pvview

Kdintroview
Stars: ✭ 300 (+32.16%)
Mutual labels:  ios-lib, ios-ui, ios-animation, onboarding
Rakuguide
The Raku Guide
Stars: ✭ 155 (-31.72%)
Mutual labels:  tutorial, guide, introduction
Iosproject
IOS综合项目,完善的框架,路由模块化设计,集成科大讯飞SDK方便iOS基本输入控件实现语音辅助输入,UI效果参照京东APP,JS与OC交互,ionic跨平台开发,MQTT 协议,即时通讯协议,视屏播放,跑马灯效果 仿美团地图定位,城市收索, 友盟分享,基础动画 增加FCUIID帮助类,引导页功能模块,照片上传 ,UIView自定义导航栏,文件下载,Masonry 案例,fmdb,数据库,sqlite,百度地图,二维码,照片上传,照片上传有进度,列表倒计时,H5和原生交互,自定义各种弹框,常见表单类型,人脸识别,列表加载图片,列表拖拽,日历操作,导航条渐变,核心动画,动画特效等等
Stars: ✭ 291 (+28.19%)
Mutual labels:  ios-lib, ios-ui, ios-animation
Showcaseview
🔦The ShowcaseView library is designed to highlight and showcase specific parts of apps to the user with an attractive and flat overlay.
Stars: ✭ 281 (+23.79%)
Mutual labels:  guide, introduction, onboarding
Core
D Language online tour (https://tour.dlang.org/) and online editor (https://run.dlang.io/)
Stars: ✭ 89 (-60.79%)
Mutual labels:  tutorial, guide, introduction
Mycoretextlabel
图文混排 , 实现图片文字混排 , 可显示常规链接比如网址,@,#话题#,手机号 , 邮箱号等 , 可以自定义链接字,设置关键字高亮等功能 . 适用于微博,微信,IM聊天对话等场景 . 实现这些功能仅用了几百行代码,耦合性也较低
Stars: ✭ 192 (-15.42%)
Mutual labels:  ios-lib, ios-ui, ios-animation
Rhplaceholder
Show pleasant loading view for your users 😍
Stars: ✭ 238 (+4.85%)
Mutual labels:  ios-lib, ios-ui, ios-animation
Hero
Elegant transition library for iOS & tvOS
Stars: ✭ 20,547 (+8951.54%)
Mutual labels:  ios-lib, ios-animation, transition-animation
React Native Onboarding Swiper
🛳 Delightful onboarding for your React-Native app
Stars: ✭ 596 (+162.56%)
Mutual labels:  tutorial, introduction, onboarding
Nvactivityindicatorview
A collection of awesome loading animations
Stars: ✭ 10,031 (+4318.94%)
Mutual labels:  ios-lib, ios-ui, ios-animation
Wobbly
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.
Stars: ✭ 150 (-33.92%)
Mutual labels:  ios-ui, ios-animation
Swiftui Tutorials
A code example and translation project of SwiftUI. / 一个 SwiftUI 的示例、翻译的教程项目。
Stars: ✭ 1,992 (+777.53%)
Mutual labels:  tutorial, ios-ui
Digital video introduction
A hands-on introduction to video technology: image, video, codec (av1, vp9, h265) and more (ffmpeg encoding).
Stars: ✭ 12,184 (+5267.4%)
Mutual labels:  tutorial, guide
Zalo.github.io
A home for knowledge that is hard to find elsewhere
Stars: ✭ 143 (-37%)
Mutual labels:  tutorial, interactive
Pharo Wiki
Wiki related to the Pharo programming language and environment.
Stars: ✭ 161 (-29.07%)
Mutual labels:  tutorial, guide
An Idiots Guide To Installing Arch On A Lenovo Carbon X1 Gen 6
so you wanted to install arch huh
Stars: ✭ 165 (-27.31%)
Mutual labels:  tutorial, guide
Cehv10 Notes
📕 Both personal and public notes for EC-Council's CEHv10 312-50, because its thousands of pages/slides of boredom, and a braindump to many
Stars: ✭ 170 (-25.11%)
Mutual labels:  tutorial, guide
Lmmediaplayer
A video and audio player with replaceable UI component.
Stars: ✭ 183 (-19.38%)
Mutual labels:  ios-lib, ios-ui
Calendarkit
📅 Calendar for Apple platforms in Swift
Stars: ✭ 2,049 (+802.64%)
Mutual labels:  ios-lib, ios-ui
Java Telegram Bot Tutorial
Java Telegram Bot Tutorial. Feel free to submit issue if you found a mistake.
Stars: ✭ 165 (-27.31%)
Mutual labels:  tutorial, guide

Onboarding demo

Installation

Using CocoaPods

Edit your Podfile and specify the dependency:

pod 'PVView', '~> 1.0.4'

Requirements

  • iOS 9.0+
  • Swift 5

Concept

  • PVItemType presents a parallax item
  • PVActionType presents an action of an item
  • PVView is separated by pages
  • Each page contains a set of PVItemType, and PVView only updates actions of items on the current page
  • On a page, each PVItemType has a set of PVActionType
  • All PVActionType are updated by progress. Progress in a page is always in [0...1] range
  • An action may has startOffset and stopOffset. These parameters describe offsets on a page where the action will begin and finish. (0 <= startOffset < stopOffset <= 1)

How to use

1. Import PVView in proper place.

import PVView

2. Create parallax item by implementing PVItemType protocol.

enum YourItem: String, PVItemType {
    case item1
    case item2

    var identifier: String {
        return self.rawValue
    }
}

3. Set PVView's delegate and implement PVViewDelegate protocol

Required delegate methods

There are 4 required methods of PVViewDelegate that you have to implement

  • Specify how many pages in PVView by implementing
func numberOfPages(in parallaxView: PVView) -> Int {
    return 2
}
  • Specify what items on a page by implementing
func parallaxView(_ parallaxView: PVView, itemsOnPage pageIndex: Int) -> [PVItemType] {
    return [YourItem.item1, .item2]
}
  • Then PVView will ask you what view will be attached to the item via:
func parallaxview(_ parallaxView: PVView, viewForItem item: PVItemType) -> UIView

Note: The view that is returned from this method will be cached for the item, and this method is only called when there is no view existed for the item in the cache

  • Finally, specify what actions will be run on an item by implementing:
func parallaxView(_ parallaxView: PVView, actionsOfItem item: PVItemType, onPage pageIndex: Int) -> [PVActionType] {
        if pageIndex == 0 {
            return [PVActionMove(fromOrigin: PVPoint(x: 50, y: 200), toOrigin: PVPoint(x: 250, y: 200))]
        }
        return []
    }

Note: In these methods, you can use currentPageIndex property of PVView to get index of page before the transition.

Optional delegate memthods

  • PVView supports both horizontal or vertical scrolling. Specify scroll direction of PVView by implementing below method (default will be horizontal):
func direction(of parallaxView: PVView) -> PVView.PVDirection
  • View of PVItemType will be automatically added as a subview of PVView by default. You can specify a container view for a view of PVItemType by implementing this method (return nil means container view is PVView)
func parallaxView(_ parallaxView: PVView, containerViewForItem item: PVItemType, onPage pageIndex: Int) -> UIView?
  • Before transition to a new page, PVView will call below method, it is your chance to do something before appearing the new page (ex: adding some animations on previous items or hiding/showing some views...)
func parallaxView(_ parallaxView: PVView, willBeginTransitionTo pageIndex: Int)
  • After finish transition to a new page, PVView will call below method, it is your chance to do something after appearing the new page (ex: setup initial state for actions of items...)
func parallaxView(_ parallaxView: PVView, didEndTransitionFrom previousPageIndex: Int?)
  • The last delegate method is:
func parallaxView(_ parallaxView: PVView, didUpdate pageProgress: Double, onPage pageIndex: Int)

This method is called continuously during scrolling to report progress in a page

4. Starting PVView

parallaxView.reload()

More

Action parameters

Action's parameters is present by PVParameters

  • startOffset: offset on page where the action will start at
  • stopOffset: offset on page where the action will stop at
  • timingFunction: an object that calculates action's progress base on a page progress

Example:

Action offsets

startOffset = 0.2, stopOffset = 0.6. The action will be started at progress = 0.2 and stoped at progress = 0.6

Timing function

Timing function

There is a built-in function called PVTimingFunction. It is same as CAMediaTimingFunction but provide us the evaluate method to calculate action's progress

You can init a PVTimingFunction by name that was defined in PVTimingFunctionName

To understand about those function names, please take a look at Ease functions

Action group

PVActionGroup presents a group of actions. Parameters of an action in the group is the parameters of the group.

Because PVActionGroup is a PVActionBasicType, so you can easily reverse all actions in the group by calling reverse method of the group

Reverse a sequence of actions

Sometime you want to reverse all actions in a sequence. There is a built in method can help:

public extension Sequence where Element: PVActionBasicType {
    func reversedActions(with newParameters: PVParameters = .default) -> [Element] {
        return self.map { $0.reverse(with: newParameters) }
    }
}

Relative point and size

You can create an action with relative points using PVPoint, absolute point will be calculated base on size of the container view

PVActionMove(fromPosition: PVPoint(x: 2, y: 0.2, isRelative: true)

You can create an action with relative sizes using PVSize, absolute size will be calculated base on size of the container view

PVActionSize(from: PVSize(width: 0.2, height: 0.2, isRelative: true),
             to: PVSize(width: 0.4, height: 0.4, isRelative: true))

Customization

Customize action

You can easy custom any actions you want by implementing PVActionType

public protocol PVActionType {
    func update(_ progress: Double, target: UIView)
}

or implement PVActionBasicType that is inherited from PVActionType

public protocol PVActionBasicType: PVActionType {
    var parameters: PVParameters { get }
    func step(_ progress: Double, target: UIView)
    func reverse(with newParameters: PVParameters) -> Self
}

Example: I wrote a custom action called LetterSpacingAction. This action will change spacing of characters in a UILabel:

struct LetterSpacingAction: PVActionBasicType {
    let parameters: PVParameters
    let fromSpacing: Double
    let toSpacing: Double
    let maxWidth: CGFloat
    init(fromSpacing: Double, toSpacing: Double, maxWidth: CGFloat, parameters: PVParameters = .default) {
        self.fromSpacing = fromSpacing
        self.toSpacing = toSpacing
        self.maxWidth = maxWidth
        self.parameters = parameters
    }
    
    func step(_ progress: Double, target: UIView) {
        guard let label = target as? UILabel else { return }
        let current = fromSpacing + (toSpacing - fromSpacing) * progress
        label.attributedText = NSAttributedString(string: label.text ?? "", attributes: [.kern : current])
        label.frame = CGRect(origin: label.frame.origin, size: label.sizeThatFits(CGSize(width: maxWidth, height: CGFloat.greatestFiniteMagnitude)))
    }
    
    func reverse(with newParameters: PVParameters) -> LetterSpacingAction {
        return LetterSpacingAction(fromSpacing: toSpacing,
                                   toSpacing: fromSpacing,
                                   maxWidth: maxWidth,
                                   parameters: newParameters)
    }
}

Customize timing function

You can create any timing functions by implementing PVTimingFunctionType

public protocol PVTimingFunctionType {
    func evaluate(_ input: Double) -> Double
}

Example: Creating an EaseOutSine function:

Ease out sine

struct EaseOutSineFunction: PVTimingFunctionType {
    func evaluate(_ input: Double) -> Double {
        return sin(input * Double.pi / 2)
    }
}

Documentation

Coming soon...😅

Contributing

This is an open source project, i can't wait to see a lot of your awesome ideas 😘

License

This code is distributed under the terms and conditions of the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].