iOS Swift Development: Lets Build That App - Creating a Carousel

iOS Swift Development: Lets Build That App - Creating a Carousel

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

Now drag the screen, to change image 13:23

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (9)

Section 1

(9 cards)

Now drag the screen, to change image 13:23

Front

Implement a protocol called UIPageViewControllerDataSource within this protocol definition, you can see it has the feature called: viewControllerbeforeViewController ViewControllerAfterViewController these methods are called upon swiping left or right knowing which view controller you should see

Back

Create imageView Now within viewDidLoad, add: background color to white add a subview of imageView add constraints to subview 3:00

Front

let imageView: UIImageView = { let iv = UIImageView() iv.contentMode = .scaleAspectFit iv.backgroundColor = UIColor.blue iv.translatesAutoresizingMaskIntoConstraints = false return iv }() view.backgroundColor = UIColor.white view.addSubview(imageView) view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v0]|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["v0": imageView])) view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["v0": imageView]))

Back

set the background color of the ProjectorPageViewController class to white

Front

view.backgroundColor = UIColor.white

Back

add image name from assets

Front

iv.image = UIImage(named: "hat01")

Back

All within ProjectorPageViewController class implement the dataSource = self within ViewDidLoad, create array of the image names, viewControllerAfterViewController, and viewControllerBeforeViewController methods rename ViewController to FrameViewController 14:16

Front

dataSource = self let imageNames = ["hat01","hat02","hat03"] let frameViewController = FrameViewController() func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { return nil } func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { return nil }

Back

In app delegates create a variable projectorPageViewController that sets it to the ProjectorPageViewController class which is the subclass of UIPageViewController 10:40

Front

let projectorPageViewController = ProjectorPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)

Back

Remove Storyboard and "Main" and then paste

Front

window = UIWindow(frame: UIScreen.main.bounds) window?.makeKeyAndVisible() window?.rootViewController = ViewController()

Back

re-assign the rootViewController from ViewController() to projectorPageViewController 11:15

Front

window?.rootViewController = projectorPageViewController

Back

Now add the swiping effect Create a ProjectorPageViewController class that inherits from UIPageViewController 9:49

Front

class ProjectorPageViewController: UIPageViewController { override func viewDidLoad() { super.viewDidLoad() } }

Back