This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// PullDownSample | |
// | |
// Created by Dinesh Kumar on 15/08/16. | |
// Copyright © 2016 Organization. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer