Picture in Picture Window for iOS
- Device orientation
- iOS11+ with iOS13 modal style support
- Swift 5.x+
- XCode 11.5+
- Over modal context
If your project is IOS13+, you must set the mainWindow parameter in the show function
PIPWKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PIPWKit'
PIPWKit is available through SPM
https://github.com/nexor-it/PIPWKit/
protocol PIPWUsable {
var initialState: PIPWState { get }
var initialPosition: PIPWPosition { get }
var pipEdgeInsets: UIEdgeInsets { get }
var pipSize: CGSize { get }
var pipShadow: PIPWShadow? { get }
var pipCorner: PIPWCorner? { get }
func didChangedState(_ state: PIPWState)
func didChangePosition(_ position: PIPWPosition)
}
open class PIPWKit {
static var isActive: Bool { return floatingWindow != nil }
static var isPIP: Bool { return state == .pip }
static var floatingWindow: PIPWViewWindow?
static var mainWindow: UIWindow?
class func show(with viewController: UIViewController, mainWindow: UIWindow? = nil, completion: (() -> Void)? = nil) { ... }
class func dismiss(animated: Bool, completion: (() -> Void)? = nil) { ... }
}
func setNeedUpdatePIPSize()
func startPIPMode()
func stopPIPMode()
class PIPViewController: UIViewController, PIPWUsable {
var initialState: PIPWState { return .pip }
var pipSize: CGSize { return CGSize(width: 200.0, height: 200.0) }
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .blue
view.layer.borderColor = UIColor.red.cgColor
view.layer.borderWidth = 1.0
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
if PIPWKit.isPIP {
PIPWKit.floatingWindow?.stopPIPMode()
} else {
PIPWKit.floatingWindow?.startPIPMode()
}
}
func didChangedState(_ state: PIPWState) {
switch state {
case .pip:
print("PIPViewController.pip")
case .full:
print("PIPViewController.full")
}
}
}
let vc = PIPViewController()
PIPWKit.show(with: vc)
PIPWKit.dismiss(animated: true)
class PIPViewController: UIViewController, PIPWUsable {
func onUpdatePIPSize(_ sender: UIButton) {
pipSize = CGSize(width: 100 + Int(arc4random_uniform(100)),
height: 100 + Int(arc4random_uniform(100)))
PIPWKit.floatingWindow?.setNeedUpdatePIPSize()
}
}
class PIPViewController: UIViewController, PIPWUsable {
func fullScreenAndPIPMode() {
if PIPWKit.isPIP {
PIPWKit.floatingWindow?.stopPIPMode()
} else {
PIPWKit.floatingWindow?.startPIPMode()
}
}
func didChangedState(_ state: PIPWState) {}
func didChangePosition(_ position: PIPWPosition) {}
}
PIPWKit is made with love by Daniele Galiotto (gali8), CIO at Nexor Technology
PIPWKit is inspired to PIPKit. PIPKit is by Taeun Kim (kofktu), https://github.com/Kofktu/PIPKit
PIPWKit (like PIPKit) is available under the MIT
license. See the LICENSE
file for more info.