Skip to content

Instantly share code, notes, and snippets.

View meyusufdemirci's full-sized avatar

Yusuf Demirci meyusufdemirci

View GitHub Profile
private var xoStickyHeaderKey: UInt8 = 0
extension UIScrollView {
public var stickyHeader: StickyHeader! {
get {
var header = objc_getAssociatedObject(self, &xoStickyHeaderKey) as? StickyHeader
if header == nil {
header = StickyHeader()
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)
}
}
let headerView = Bundle.main.loadNibNamed("MyHeaderView", owner: nil, options: nil)?.first as! MyHeaderView
tableview.stickyHeader.view = headerView
tableview.stickyHeader.height = headerView.frame.height
tableview.stickyHeader.minimumHeight = 64
navigationView.frame = CGRect(x: 0, y: 0, width: headerView.frame.width, height: headerView.frame.height)
navigationView.backgroundColor = .green
navigationView.alpha = 0
table.stickyHeader.view = navigationView
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset.y
let changeStartOffset: CGFloat = -180
let changeSpeed: CGFloat = 100
navigationView.alpha = min(1.0, (offset - changeStartOffset) / changeSpeed)
}
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
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("Notification registration is success.")
if #available(iOS 10.0, *) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print(deviceTokenString)
} else {
let tokenParts = deviceToken.map { data -> String in
return String(format: "%02.2hhx", data)
{
"aps":{
"alert":"Test",
"sound":"default",
"badge":1,
"actionType":"ana_sayfa"
}
}