Swift Swipe Navigation Table Views

Swift Swipe Navigation Table Views

Following are the steps to use XLPagerTabStrip Library in your project :

Step 1: Drag a VC on Storyboard (Supposedly Intial VC) and drag a Container View on this VC(fully occupying the VC). Drag another empty VC (define its class as "myPagerStrip" which will be created in next step). Now Control drag from Container View and choose embed and define identifier of this Storyboard Embed segue as "showMyPagerStrip"

Step 2: Create a new Swift file named "myPagerStrip.swift" with following code :-

Note: Any doubt with below code, refer the github link already mentioned above, everything is explained there.

import XLPagerTabStrip

class myPagerStrip: ButtonBarPagerTabStripViewController {

override func viewDidLoad() {

settings.style.buttonBarBackgroundColor = UIColor.yellowColor()

// selected bar view is created programmatically so it's important to set up the following 2 properties properly
settings.style.selectedBarBackgroundColor = UIColor.blackColor()
//settings.style.selectedBarHeight: CGFloat = 5

// each buttonBar item is a UICollectionView cell of type ButtonBarViewCell
settings.style.buttonBarItemBackgroundColor = UIColor.redColor()
settings.style.buttonBarItemFont = UIFont.systemFontOfSize(18)
// helps to determine the cell width, it represent the space before and after the title label
// settings.style.buttonBarItemLeftRightMargin: CGFloat = 8
settings.style.buttonBarItemTitleColor = UIColor.whiteColor()
// in case the barView items do not fill the screen width this property stretch the cells to fill the screen
settings.style.buttonBarItemsShouldFillAvailiableWidth = true

changeCurrentIndexProgressive = { (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
guard changeCurrentIndex == true else { return }

oldCell?.label.textColor = UIColor(white: 1, alpha: 0.6)
newCell?.label.textColor = .whiteColor()

if animated {
UIView.animateWithDuration(0.1, animations: { () -> Void in
newCell?.transform = CGAffineTransformMakeScale(1.0, 1.0)
oldCell?.transform = CGAffineTransformMakeScale(0.8, 0.8)
})
}
else {
newCell?.transform = CGAffineTransformMakeScale(1.0, 1.0)
oldCell?.transform = CGAffineTransformMakeScale(0.8, 0.8)
}
}

super.viewDidLoad()
}

override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {

let child_1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("tableViewOne") // First Table View

let child_2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("tableViewTwo") // Second Table View

let child_3 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("tableViewThree") // Third Table View

let childVC = [child_1,child_2, child_3]

return childVC

}

override func reloadPagerTabStripView() {
super.reloadPagerTabStripView()
}

}

Step 3: Drag 3 more VC on Storyboard and create 3 Cocoa Class files namely tableViewOne.swift, tableViewTwo.swift and tableViewThree.swift with Storyboard IDs as "tableViewOne","tableViewTwo", "tableViewThree".//(As mentioned in above code for child_1,child_2 and child_3)

Note: Assuming all 3 tableViews or required tableViews are setup with required data.

Step 4: Inherit "IndicatorInfoProvider" in each of the tableViews (perform after step 5) i.e.

class tableViewOne: UIViewController,IndicatorInfoProvider

Step 5: Import XLPagerTabStrip in each of this files and also add following function in each tableView:-

func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: "My Child title 1")
}

Now, you are done. Simply Run the project in Simulator or Actual device.:)

In case having trouble with table Views, following is code for tableViewOne.swift for reference :-

import UIKit
import XLPagerTabStrip

class tableViewOne: UIViewController,IndicatorInfoProvider {

@IBOutlet var tableView: UITableView!
var dummyData = ["data 0","data 001","data try"]

override func viewDidLoad() {
super.viewDidLoad()

}

func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: "My Child title 1")
}

}
extension tableViewOne: UITableViewDataSource, UITableViewDelegate {

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return dummyData.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell")! as UITableViewCell

cell.textLabel!.text = dummyData[indexPath.row]

return cell;
}

}

Navigate/Swipe between articles in section using table view controller

Basically, you will need to create

  • a global storage for your articles, let's call it articles.
    According to articles you can populate your tableView.
  • add a swipe gesture recognizer to your opened article page
  • whenever you swipes from right to left, you push a new viewcontroller to your navigation stack, and setup this viewcontroller with the next item of articles.

Keep TabBar Large Title on swipe swift

The title will collapse on scroll as long as the root view is scrollable, i.e. is a scrollView or a view which embeds a UIScrollView.

To achieve what you want in the particular case you'd need to add a dummy view ahead of your tableView in the view hierarchy.

I've found your question while searching how to achieve the opposite /p>

table view slides up under navigation bar when user taps row

Because you're presenting view controllers in a container which is less than the full size of the screen you need to set

self.pageViewController.definesPresentationContext = YES; 

viewControllerWhichIsApageInPageController.modalPresentationStyle = UIModalPresentationCurrentContext

Swift Navigation Controller swipe to go back anywhere

Based on your indications a normal gesture recognizer on your tableview is enough.

I would do something like this:

override func viewDidLoad() {
super.viewDidLoad()

let gesture = UISwipeGestureRecognizer(target: self, action: #selector(dismiss(fromGesture:)))
tableView.addGestureRecognizer(gesture)
}

@objc func dismiss(fromGesture gesture: UISwipeGestureRecognizer) {
//Your dismiss code
//Here you should implement your checks for the swipe gesture
}

And if you want to disable the default behavior of the back gesture:

navigationController?.interactivePopGestureRecognizer?.isEnabled = false

I hope it helped. :)

How to swipe out of table view controller (not the cells) - iPhone

To control gestures on a VC, you'll need your own subclass. Create a new objective-c object named like MyTableViewController. Xcode lets you specify a superclass when creating the files, use UITableViewController.

Xcode provides some template code in the new files -- leave that alone to begin with. In storyboard, I think the tab you're trying to fix has a navigation (vc) whose root vc is a UITableViewController.

Select that table vc and select the Identity inspector (upper right, third tab from the left). You should see a section called custom class. The current class is probably UITableViewController. Change that to MyTableViewController, or whatever you named the new class.

Build and run. Now you control that table vc. Back in it's implementation file, you can add your gesture code in viewDidLoad:.



Related Topics



Leave a reply



Submit