Skip to content

Instantly share code, notes, and snippets.

View hudinwal's full-sized avatar

Dinesh Kumar hudinwal

  • Infoedge India Pvt. Ltd.
  • Noida
View GitHub Profile
#import <SafariServices/SafariServices.h>
- (IBAction)safariButtonTapped:(UIBarButtonItem *)sender {
SFSafariViewController * safariViewController = NSURL * initialURL = [NSURL URLWithString:@"https://www.google.co.in"];
[[SFSafariViewController alloc]initWithURL:initialURL];
safariViewController.navigationItem.title = @"Google";
safariViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationController pushViewController:safariViewController animated:YES];
}
// Create a lazy table view
lazy var pullDownTableView : UITableView = {
let pullDownTableView = UITableView(frame:self.view.frame)
pullDownTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell_id")
pullDownTableView.delegate = self
pullDownTableView.dataSource = self
pullDownTableView.rowHeight = 80.0
pullDownTableView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
return pullDownTableView
}()
override func viewDidLoad() {
super.viewDidLoad()
// Create and add the pull down table view
self.view.addSubview(pullDownTableView)
//Set background color to contrasting color
view.backgroundColor = UIColor.darkGrayColor()
pullDownTableView.backgroundColor = UIColor.clearColor()
var topOffset: CGFloat = 0.0
private let kTopWindowAspectRatio : CGFloat = 3.0/4.0
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// Calculate the top offset and set it if not corectly set
if(topOffset != CGRectGetWidth(pullDownTableView.bounds) * kTopWindowAspectRatio) {
topOffset = CGRectGetWidth(pullDownTableView.bounds) * kTopWindowAspectRatio
// Setup table view insets and offsets
let topInset = CGRectGetHeight(pullDownTableView.bounds)
pullDownTableView.contentInset = UIEdgeInsetsMake(topInset, 0, 0, 0);
extension ViewController : UIScrollViewDelegate,UITableViewDelegate {
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let yInset = scrollView.contentInset.top
if scrollView.contentOffset.y > -topOffset && targetContentOffset.memory.y < -topOffset {
targetContentOffset.memory.y = scrollView.contentOffset.y
scrollView.setContentOffset(CGPointMake(0, -topOffset), animated: true)
}
else if -topOffset > targetContentOffset.memory.y && targetContentOffset.memory.y > (-topOffset + (topOffset - yInset)/2) {
// Custom table view class so not to handle touches that cannot be handled by the content view.
class TableView: UITableView {
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
return subviews.first?.hitTest(point, withEvent: event)
}
}
private(set) lazy var swipeDownGesture: UISwipeGestureRecognizer = {
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.handleSwipeGestures(_:)))
swipeGesture.direction = .Down
return swipeGesture
}()
private(set) lazy var swipeUpGesture: UISwipeGestureRecognizer = {
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.handleSwipeGestures(_:)))
swipeGesture.direction = .Up
return swipeGesture
}()
//
// ViewController.swift
// PullDownSample
//
// Created by Dinesh Kumar on 15/08/16.
// Copyright © 2016 Organization. All rights reserved.
//
import UIKit
lazy var moveableImageView: UIImageView = {
let imageView = UIImageView(frame: self.view.frame)
imageView.contentMode = .ScaleAspectFit
imageView.image = UIImage(named: "Image")
imageView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
var topOffset: CGFloat = 0.0
private let kTopWindowAspectRatio : CGFloat = 3.0/4.0
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// Calculate the top offset and set it if not corectly set
if(topOffset != CGRectGetWidth(pullDownTableView.bounds) * kTopWindowAspectRatio) {
topOffset = CGRectGetWidth(pullDownTableView.bounds) * kTopWindowAspectRatio
// Setup table view insets and offsets
let topInset = CGRectGetHeight(pullDownTableView.bounds)