• Guest
HabraHabr
  • Main
  • Users

  • Development
    • Programming
    • Information Security
    • Website development
    • JavaScript
    • Game development
    • Open source
    • Developed for Android
    • Machine learning
    • Abnormal programming
    • Java
    • Python
    • Development of mobile applications
    • Analysis and design of systems
    • .NET
    • Mathematics
    • Algorithms
    • C#
    • System Programming
    • C++
    • C
    • Go
    • PHP
    • Reverse engineering
    • Assembler
    • Development under Linux
    • Big Data
    • Rust
    • Cryptography
    • Entertaining problems
    • Testing of IT systems
    • Testing Web Services
    • HTML
    • Programming microcontrollers
    • API
    • High performance
    • Developed for iOS
    • CSS
    • Industrial Programming
    • Development under Windows
    • Image processing
    • Compilers
    • FPGA
    • Professional literature
    • OpenStreetMap
    • Google Chrome
    • Data Mining
    • PostgreSQL
    • Development of robotics
    • Visualization of data
    • Angular
    • ReactJS
    • Search technologies
    • Debugging
    • Test mobile applications
    • Browsers
    • Designing and refactoring
    • IT Standards
    • Solidity
    • Node.JS
    • Git
    • LaTeX
    • SQL
    • Haskell
    • Unreal Engine
    • Unity3D
    • Development for the Internet of things
    • Functional Programming
    • Amazon Web Services
    • Google Cloud Platform
    • Development under AR and VR
    • Assembly systems
    • Version control systems
    • Kotlin
    • R
    • CAD/CAM
    • Customer Optimization
    • Development of communication systems
    • Microsoft Azure
    • Perfect code
    • Atlassian
    • Visual Studio
    • NoSQL
    • Yii
    • Mono и Moonlight
    • Parallel Programming
    • Asterisk
    • Yandex API
    • WordPress
    • Sports programming
    • Lua
    • Microsoft SQL Server
    • Payment systems
    • TypeScript
    • Scala
    • Google API
    • Development of data transmission systems
    • XML
    • Regular expressions
    • Development under Tizen
    • Swift
    • MySQL
    • Geoinformation services
    • Global Positioning Systems
    • Qt
    • Dart
    • Django
    • Development for Office 365
    • Erlang/OTP
    • GPGPU
    • Eclipse
    • Maps API
    • Testing games
    • Browser Extensions
    • 1C-Bitrix
    • Development under e-commerce
    • Xamarin
    • Xcode
    • Development under Windows Phone
    • Semantics
    • CMS
    • VueJS
    • GitHub
    • Open data
    • Sphinx
    • Ruby on Rails
    • Ruby
    • Symfony
    • Drupal
    • Messaging Systems
    • CTF
    • SaaS / S+S
    • SharePoint
    • jQuery
    • Puppet
    • Firefox
    • Elm
    • MODX
    • Billing systems
    • Graphical shells
    • Kodobred
    • MongoDB
    • SCADA
    • Hadoop
    • Gradle
    • Clojure
    • F#
    • CoffeeScript
    • Matlab
    • Phalcon
    • Development under Sailfish OS
    • Magento
    • Elixir/Phoenix
    • Microsoft Edge
    • Layout of letters
    • Development for OS X
    • Forth
    • Smalltalk
    • Julia
    • Laravel
    • WebGL
    • Meteor.JS
    • Firebird/Interbase
    • SQLite
    • D
    • Mesh-networks
    • I2P
    • Derby.js
    • Emacs
    • Development under Bada
    • Mercurial
    • UML Design
    • Objective C
    • Fortran
    • Cocoa
    • Cobol
    • Apache Flex
    • Action Script
    • Joomla
    • IIS
    • Twitter API
    • Vkontakte API
    • Facebook API
    • Microsoft Access
    • PDF
    • Prolog
    • GTK+
    • LabVIEW
    • Brainfuck
    • Cubrid
    • Canvas
    • Doctrine ORM
    • Google App Engine
    • Twisted
    • XSLT
    • TDD
    • Small Basic
    • Kohana
    • Development for Java ME
    • LiveStreet
    • MooTools
    • Adobe Flash
    • GreaseMonkey
    • INFOLUST
    • Groovy & Grails
    • Lisp
    • Delphi
    • Zend Framework
    • ExtJS / Sencha Library
    • Internet Explorer
    • CodeIgniter
    • Silverlight
    • Google Web Toolkit
    • CakePHP
    • Safari
    • Opera
    • Microformats
    • Ajax
    • VIM
  • Administration
    • System administration
    • IT Infrastructure
    • *nix
    • Network technologies
    • DevOps
    • Server Administration
    • Cloud computing
    • Configuring Linux
    • Wireless technologies
    • Virtualization
    • Hosting
    • Data storage
    • Decentralized networks
    • Database Administration
    • Data Warehousing
    • Communication standards
    • PowerShell
    • Backup
    • Cisco
    • Nginx
    • Antivirus protection
    • DNS
    • Server Optimization
    • Data recovery
    • Apache
    • Spam and antispam
    • Data Compression
    • SAN
    • IPv6
    • Fidonet
    • IPTV
    • Shells
    • Administering domain names
  • Design
    • Interfaces
    • Web design
    • Working with sound
    • Usability
    • Graphic design
    • Design Games
    • Mobile App Design
    • Working with 3D-graphics
    • Typography
    • Working with video
    • Work with vector graphics
    • Accessibility
    • Prototyping
    • CGI (graphics)
    • Computer Animation
    • Working with icons
  • Control
    • Careers in the IT industry
    • Project management
    • Development Management
    • Personnel Management
    • Product Management
    • Start-up development
    • Managing the community
    • Service Desk
    • GTD
    • IT Terminology
    • Agile
    • Business Models
    • Legislation and IT-business
    • Sales management
    • CRM-systems
    • Product localization
    • ECM / EDS
    • Freelance
    • Venture investments
    • ERP-systems
    • Help Desk Software
    • Media management
    • Patenting
    • E-commerce management
    • Creative Commons
  • Marketing
    • Conferences
    • Promotion of games
    • Internet Marketing
    • Search Engine Optimization
    • Web Analytics
    • Monetize Web services
    • Content marketing
    • Monetization of IT systems
    • Monetize mobile apps
    • Mobile App Analytics
    • Growth Hacking
    • Branding
    • Monetize Games
    • Display ads
    • Contextual advertising
    • Increase Conversion Rate
  • Sundry
    • Reading room
    • Educational process in IT
    • Research and forecasts in IT
    • Finance in IT
    • Hakatonas
    • IT emigration
    • Education abroad
    • Lumber room
    • I'm on my way

The story of one view controller that wanted to show up beautifully

There was a modest view controller
VCYellow
. And he had no picture, no text, not even a tiny business logic. He lived a normal view-controller life.
ancient scrolls how to use the spell and began to prepare.
 
I wrote myself a cheat sheet with the spell itself, so as not to forget:
 
extension VCYellow: UIViewControllerTransitioningDelegate {
func animationController (forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return AnimatorPresent (startFrame: self.startFrame)
}
func animationController (forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return AnimatorDismiss (endFrame: self.startFrame)
}
}

 

In it, he carefully painted that for the show you need to use the animator AnimatorPresent , and when closing AnimatorDismiss .
 
Well, as a help to both animators it was decided to transfer the frame of the main button from VCMain


 

And then he himself was morally adjusted. Because without a right attitude, as is known, no magic works:


 
    override func viewDidLoad () {
super.viewDidLoad ()
self.modalPresentationStyle = .custom
self.transitioningDelegate = self
}

 

He asked his friend VCMain Present yourself to check how the magic works and it worked no way

 
It turned out that AnimatorPresent and AnimatorDismiss do not appear by themselves.


 

It was already late to stop, and our hero decided to create the necessary animators. I dig in the necessary section ancient scrolls and learned that to create an animator, two things are enough.


 

First, you need to set the time allocated for the animation:


 
    func transitionDuration (using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return ???r3r3341.}

 

and secondly designate the animation itself:


 
  
func animateTransition (using transitionContext: UIViewControllerContextTransitioning) {
//1
guard let vcTo = transitionContext.viewController (forKey: .to),
let snapshot = vcTo.view.snapshotView (afterScreenUpdates: true) else {
return
}
//2
let vContainer = transitionContext.containerView
//3
vcTo.view.isHidden = true
vContainer.addSubview (vcTo.view)
//4
snapshot.frame = self.startFrame
vContainer.addSubview (snapshot)
UIView.animate (withDuration: 0.? animations: {
//5
Snapshot.frame = (transitionContext.finalFrame (for: vcTo))
}, Completion: {success in
//6
VcTo. view.isHidden = false
snapshot.removeFromSuperview ()
transitionContext.completeTransition (true)
})
}

 
  1.  
  2. Pull out the presented view controller (in our case VCYellow) and take it. Photo is needed to simplify the animation.  
  3. Get a view on which will be animated witchcraft. Let's call it the context.  
  4. Hook the final controller's view to the context and hide it. Show  
  5. it was decided after the animation is over.  
  6. Prepare a picture for animation. Reduce to the initial size and throw the context.  
  7. Split the picture into the entire screen, thereby animating the presentation process.  
  8. After the end of the animation show the real view of the final controller,  
  9. get rid of the pictures and report that the action is over.  

 

As a result, there was such an animator for the show:


 
    import UIKit
class AnimatorPresent: NSObject, UIViewControllerAnimatedTransitioning {
let startFrame: CGRect
init (startFrame: CGRect) {
self.startFrame = startFrame
}
func transitionDuration (using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return ???r3r3341.}
func animateTransition (using transitionContext: UIViewControllerContextTransitioning) {
guard let vcTo = transitionContext.viewController (forKey: .to),
let snapshot = vcTo.view.snapshotView (afterScreenUpdates: true) else {
return
}
let vContainer = transitionContext.containerView
vcTo.view.isHidden = true
vContainer.addSubview (vcTo.view)
snapshot.frame = self.startFrame
vContainer.addSubview (snapshot)
UIView.animate (withDuration: 0.? animations: {
.snapshot.frame = (transitionContext.finalFrame (for: vcTo))
}, Completion: {success in
.vcTo.view.isHidden = false
Snapshot.removeFromSuperview ()
TransitionContext.completeTransition (true)
})
}
}

 

And after that it was easy to write an animator for hiding, which does about the same thing, but on the contrary:


 
    import UIKit
class AnimatorDismiss: NSObject, UIViewControllerAnimatedTransitioning {
let endFrame: CGRect
init (endFrame: CGRect) {
self.endFrame = endFrame
}
func transitionDuration (using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return ???r3r3341.}
func animateTransition (using transitionContext: UIViewControllerContextTransitioning) {
guard let vcTo = transitionContext.viewController (forKey: .to),
let vcFrom = transitionContext.viewController (forKey: .from),
let snapshot = vcFrom.view.snapshotView (afterScreenUpdates: true) else {
return
}
let vContainer = transitionContext.containerView
vContainer.addSubview (vcTo.view)
vContainer.addSubview (snapshot)
vcFrom.view.isHidden = true
UIView.animate (withDuration: 0.? animations: {
? snapshot.frame = self.endFrame
}, Completion: {success in
TransitionContext.completeTransition (true)
})
}
}

 
Having finished all the dodings,
VCYellow
again asked his friend
VCMain
present yourself and a miracle!
 
The story of one view controller that wanted to show up beautifully
 
Magic worked! Dream
VCYellow
has come true! Now he can show up and hide as he wants and nothing will limit his imagination!
 
The project-example can be downloaded here
 
The article I used for inspiration is here

It may be interesting

  • Comments
  • About article
  • Similar news
This publication has no comments.

weber

Author

29-09-2018, 19:30

Publication Date

Development / Programming

Category
  • Comments: 0
  • Views: 260
Controller, easy! We take out the code
How to save the project from extra
Architecture creation: working with iOS
Testing the presenter using PromiseKit
Composition UIViewController-s and
We write UI Snapchat'a on Swift'e
Write a comment
Name:*
E-Mail:


Comments
this is really nice to read..informative post is very good to read..thanks a lot! How is the cost of house cleaning calculated?
Yesterday, 17:14

Legend SEO

It’s very informative and you are obviously very knowledgeable in this area. You have opened my eyes to varying views on this topic with interesting and solid content.

entegrasyon programları
Yesterday, 17:09

taxiseo2

I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.

entegrasyon programları
Yesterday, 17:02

taxiseo2

I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work...먹튀

Yesterday, 16:50

raymond weber

Lose Weight Market provides the best fitness tips, workout guides, keto recipes and diet plans, yoga workout routine and plans, healthy recipes, and more! Check Out: Lose Weight Market


Corvus Health provides medical training services as well as recruiting high quality health workers for you or placing our own best team in your facility. Check Out: Health Workforce Recruitment




I.T HATCH offers a wide range of IT services including remote access setup, small business servers, data storage solutions, IT strategy services, and more. Check Out: IT strategy services
Yesterday, 22:33

noorseo

Adv
Website for web developers. New scripts, best ideas, programming tips. How to write a script for you here, we have a lot of information about various programming languages. You are a webmaster or a beginner programmer, it does not matter, useful articles will help to make your favorite business faster.

Login

Registration Forgot password