Skip to content

Instantly share code, notes, and snippets.

View meyusufdemirci's full-sized avatar

Yusuf Demirci meyusufdemirci

View GitHub Profile
public class StickyHeader: NSObject {
/**
The view containing the provided header.
*/
private(set) lazy var contentView: StickyHeaderView = {
let view = StickyHeaderView()
view.parent = self
view.clipsToBounds = true
return view
internal class StickyHeaderView: UIView {
weak var parent: StickyHeader?
internal static var KVOContext = 0
override func willMove(toSuperview view: UIView?) {
if let view = self.superview, view.isKind(of:UIScrollView.self), let parent = self.parent {
view.removeObserver(parent, forKeyPath: "contentOffset", context: &StickyHeaderView.KVOContext)
}
}
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// MARK: Outlets
@IBOutlet weak var table: UITableView!
// MARK: Properties
var navigationView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
import UIKit
enum ScreenType {
case iPhone4
case iPhone5
case iPhone6
case iPhonePlus
case iPhoneX
case unknown
}
import UIKit
import AVKit
class ViewController: UIViewController {
let playerController = AVPlayerViewController()
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(onRotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
@objc func onRotated() {
// portrait
if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) {
}
// landscape
else if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) {
@objc func onRotated() {
// portrait
if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) {
playerController.view.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 250)
}
// landscape
else if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) {
playerController.view.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
import UIKit
import AVKit
class ViewController: UIViewController {
let playerController = AVPlayerViewController()
override func viewDidLoad() {
super.viewDidLoad()
import UIKit
import StoreKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {