Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

More Related Content

You Might Also Like

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Scroll views

  1. 1. Unit 4—Lesson 4: Scroll Views
  2. 2. Scroll views
  3. 3. UIScrollView • For displaying more content than can fit on the screen • Users scroll within the content by making swiping gestures • Content can optionally be zoomed with a pinch gesture • UIScrollView needs to know the size of the content
  4. 4. Scroll views
  5. 5. Define scroll view frame Scroll views in Interface Builder
  6. 6. Add constraints Scroll views in Interface Builder
  7. 7. Define content view using stack view Scroll views in Interface Builder
  8. 8. Programatic constraints Scroll views in Interface Builder imageView.centerXAnchor.constraints(equalTo: scrollView.contentLayoutGuide.centerXAnchor) imageView.centerYAnchor.constraints(equalTo: scrollView.contentLayoutGuide.centerYAnchor)
  9. 9. Create the form and add fields Scroll views in Interface Builder
  10. 10. Keyboard issues Sent a notification when the keyboard has been shown or 
 will be hidden Register for keyboard notifications func registerForKeyboardNotifications() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown(_:)), name: .UIKeyboardDidShow, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(_:)), name: .UIKeyboardWillHide, object: nil) }
  11. 11. func keyboardWasShown(_ notificiation: NSNotification) { guard let info = notificiation.userInfo, let keyboardFrameValue = info[UIKeyboardFrameBeginUserInfoKey] as? NSValue else { return } let keyboardFrame = keyboardFrameValue.cgRectValue let keyboardSize = keyboardFrame.size let contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0) scrollView.contentInset = contentInsets scrollView.scrollIndicatorInsets = contentInsets } func keyboardWillBeHidden(_ notification: NSNotification) { let contentInsets = UIEdgeInsets.zero scrollView.contentInset = contentInsets scrollView.scrollIndicatorInsets = contentInsets }
  12. 12. Content insets Allows you to pad the content at the top and bottom of the scroll view Useful if you have toolbars floating above your scroll view scrollview.contentInset.top .bottom .left .right
  13. 13. Scroll indicator let contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0) scrollView.contentInset = contentInsets scrollView.scrollIndicatorInsets = contentInsets
  14. 14. Scroll View family UITableView UICollectionView
  15. 15. Scroll Views Unit 4—Lesson 4 Learn how to use a UIScrollView to display content that's larger than the device screen and allow the user to interact with it.
  16. 16. Lab: I Spy Unit 4—Lesson 4 Implement a scroll view on an image view that will enable users to zoom in and pan an image. Your app will have a single view with a single picture.
  17. 17. © 2017 Apple Inc. This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.

×