Is There a Public API for Card View UI That Can Be Seen Across iOS 10

What is the name of this dismissable viewcontrollable in iOS?

Its a custom modal view controller which you can animate in with UIViewControllerTransitionCoordinator. If you don't want to mess with the code then consider using the Hero pod which can acheive a similar effect.

How can I mimic the bottom sheet from the Maps app?

I don't know how exactly the bottom sheet of the new Maps app, responds to user interactions. But you can create a custom view that looks like the one in the screenshots and add it to the main view.

I assume you know how to:

1- create view controllers either by storyboards or using xib files.

2- use googleMaps or Apple's MapKit.

Example

1- Create 2 view controllers e.g, MapViewController and BottomSheetViewController. The first controller will host the map and the second is the bottom sheet itself.

Configure MapViewController

Create a method to add the bottom sheet view.

func addBottomSheetView() {
// 1- Init bottomSheetVC
let bottomSheetVC = BottomSheetViewController()

// 2- Add bottomSheetVC as a child view
self.addChildViewController(bottomSheetVC)
self.view.addSubview(bottomSheetVC.view)
bottomSheetVC.didMoveToParentViewController(self)

// 3- Adjust bottomSheet frame and initial position.
let height = view.frame.height
let width = view.frame.width
bottomSheetVC.view.frame = CGRectMake(0, self.view.frame.maxY, width, height)
}

And call it in viewDidAppear method:

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
addBottomSheetView()
}

Configure BottomSheetViewController

1) Prepare background

Create a method to add blur and vibrancy effects

func prepareBackgroundView(){
let blurEffect = UIBlurEffect.init(style: .Dark)
let visualEffect = UIVisualEffectView.init(effect: blurEffect)
let bluredView = UIVisualEffectView.init(effect: blurEffect)
bluredView.contentView.addSubview(visualEffect)

visualEffect.frame = UIScreen.mainScreen().bounds
bluredView.frame = UIScreen.mainScreen().bounds

view.insertSubview(bluredView, atIndex: 0)
}

call this method in your viewWillAppear

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
prepareBackgroundView()
}

Make sure that your controller's view background color is clearColor.

2) Animate bottomSheet appearance

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

UIView.animateWithDuration(0.3) { [weak self] in
let frame = self?.view.frame
let yComponent = UIScreen.mainScreen().bounds.height - 200
self?.view.frame = CGRectMake(0, yComponent, frame!.width, frame!.height)
}
}

3) Modify your xib as you want.

4) Add Pan Gesture Recognizer to your view.

In your viewDidLoad method add UIPanGestureRecognizer.

override func viewDidLoad() {
super.viewDidLoad()

let gesture = UIPanGestureRecognizer.init(target: self, action: #selector(BottomSheetViewController.panGesture))
view.addGestureRecognizer(gesture)

}

And implement your gesture behaviour:

func panGesture(recognizer: UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.view)
let y = self.view.frame.minY
self.view.frame = CGRectMake(0, y + translation.y, view.frame.width, view.frame.height)
recognizer.setTranslation(CGPointZero, inView: self.view)
}

Scrollable Bottom Sheet:

If your custom view is a scroll view or any other view that inherits from, so you have two options:

First:

Design the view with a header view and add the panGesture to the header. (bad user experience).

Second:

1 - Add the panGesture to the bottom sheet view.

2 - Implement the UIGestureRecognizerDelegate and set the panGesture delegate to the controller.

3- Implement shouldRecognizeSimultaneouslyWith delegate function and disable the scrollView isScrollEnabled property in two case:

  • The view is partially visible.
  • The view is totally visible, the scrollView contentOffset property is 0 and the user is dragging the view downwards.

Otherwise enable scrolling.

  func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
let gesture = (gestureRecognizer as! UIPanGestureRecognizer)
let direction = gesture.velocity(in: view).y

let y = view.frame.minY
if (y == fullView && tableView.contentOffset.y == 0 && direction > 0) || (y == partialView) {
tableView.isScrollEnabled = false
} else {
tableView.isScrollEnabled = true
}

return false
}

NOTE

In case you set .allowUserInteraction as an animation option, like in the sample project, so you need to enable scrolling on the animation completion closure if the user is scrolling up.

Sample Project

I created a sample project with more options on this repo which may give you better insights about how to customise the flow.

In the demo, addBottomSheetView() function controls which view should be used as a bottom sheet.

Sample Project Screenshots

- Partial View

Sample Image

- FullView

Sample Image

- Scrollable View

Sample Image

Is there any UI library in Android ,similar to the UI view of , iOS HealthBook/Passbook app

there is not direct library by which you can make it , you have to use custom layout .

iOS Swift: How to achieve stack of cards like user interface?

As suggested in my comment you could create a container view controller where you'd add your child view controllers. How you present and remove them it's up to you. I added a swipe gesture to remove them from childViewControllers array one by one, but you could elaborate with animations, etc. Here is the example:

import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let swipeGesturRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(didSwipe))
swipeGesturRecognizer.direction = .left
view.addGestureRecognizer(swipeGesturRecognizer)

var index = 0
let amount = 5
while index < amount {
let childViewController = UIViewController()
childViewController.view
.translatesAutoresizingMaskIntoConstraints = true
let hue = 1.0 / CGFloat(index)
childViewController.view.backgroundColor = UIColor(hue: hue, saturation: 0.5, brightness: 0.5, alpha: 1)
childViewController.view.frame = self.view.bounds.insetBy(dx: CGFloat(amount - index) * 10, dy: 80.0).offsetBy(dx: 0.0, dy: -CGFloat(amount - index) * 10.0)
childViewController.view.layer.borderColor = UIColor.blue.cgColor
childViewController.view.layer.borderWidth = 1.0
self.view.addSubview(childViewController.view)
self.addChildViewController(childViewController)
childViewController.didMove(toParentViewController: self)
index += 1
}
}

// Removes child view controlelrs one by one when swiped left
@objc func didSwipe() {
guard let childViewController = childViewControllers.last else {
return
}
childViewController.willMove(toParentViewController: nil)
childViewController.view.removeFromSuperview()
childViewController.removeFromParentViewController()
}
}

Name of iOS ui element

Even though it's common, it is not a standard UIKit element. It's a custom presented view controller (not a standard configuration). You'll need a custom transition animation and presentation controller along with gesture recognizers for dismissal. (There are lots of tutorials showing you how to do that.)

New in iOS 13, all presented view controllers have this general configuration by default (called "sheet" or "card"), but not half-screen like the one you've shown (they almost fill the screen).

How do I inspect the view hierarchy in iOS?

Xcode 6 now has 3D view hierarchy inspection built in like Reveal App and Spark Inspector.

Sample Image

Click on the "Debug View Hierarchy" button while your app is running to pause execution and inspect the views at the current moment.

Sample Image

More info at Apple's documentation.

Presenting modal in iOS 13 fullscreen

With iOS 13, as stated in the Platforms State of the Union during the WWDC 2019, Apple introduced a new default card presentation. In order to force the fullscreen you have to specify it explicitly with:

let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen //or .overFullScreen for transparency
self.present(vc, animated: true, completion: nil)


Related Topics



Leave a reply



Submit