<commit_before>//
//  GalleryPresentTransition.swift
//  ImageViewer
//
//  Created by <NAME> on 02/03/2016.
//  Copyright © 2016 MailOnline. All rights reserved.
//

import UIKit

class GalleryPresentTransition: NSObject, UIViewControllerAnimatedTransitioning {
    
    private let duration: NSTimeInterval
    private let displacedView: UIView
    var headerView: UIView?
    var footerView: UIView?
    var closeView: UIView?
    var completion: (() -> Void)?
    
    init(duration: NSTimeInterval, displacedView: UIView) {
        
        self.duration = duration
        self.displacedView = displacedView
    }
    
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return duration
    }
    
    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        
        //get the temporary container view that facilitates all the animations
        let transitionContainerView = transitionContext.containerView()! //Apple, Apple..
        
        //get the target controller's root view and add it to the scene
        let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
        transitionContainerView.addSubview(toViewController.view)
        
        //make it align with scene geometry
        toViewController.view.frame = UIScreen.mainScreen().bounds
        
        //prepare transition of background from transparent to full black
        toViewController.view.backgroundColor = UIColor.blackColor()
        toViewController.view.alpha = 0.0
        
        if isPortraitOnly() {
            toViewController.view.transform = rotationTransform()
            toViewController.view.bounds = rotationAdjustedBounds()
        }
        
        //make a screenshot of displaced view so we can create our own animated view
        let screenshot = screenshotFromView(displacedView)
        
        //make the original displacedView hidden, we can give an illusion it is moving away from its parent view
        displacedView.hidden = true
        
        //hide the gallery views
        headerView?.alpha = 0.0
        footerView?.alpha = 0.0
        closeView?.alpha = 0.0
        
        //translate coordinates of displaced view into our coordinate system (which is now the transition container view) so that we match the animation start position on device screen level
        let origin = transitionContainerView.convertPoint(CGPoint.zero, fromView: displacedView)
        
        //create UIImageView with screenshot
        let animatedImageView = UIImageView()
        animatedImageView.bounds = displacedView.bounds
        animatedImageView.frame.origin = origin
        animatedImageView.image = screenshot
        
        //put it into the container
        transitionContainerView.addSubview(animatedImageView)
        
        UIView.animateWithDuration(self.duration, animations: { [weak self] () -> Void in
            
            if isPortraitOnly() == true {
                animatedImageView.transform = rotationTransform()
            }
                //animate it into the center (with optionaly rotating) - that basically includes changing the size and position
            <commit_msg>Removed warning for weak self.<commit_after>//
//  GalleryPresentTransition.swift
//  ImageViewer
//
//  Created by <NAME> on 02/03/2016.
//  Copyright © 2016 MailOnline. All rights reserved.
//

import UIKit

class GalleryPresentTransition: NSObject, UIViewControllerAnimatedTransitioning {
    
    private let duration: NSTimeInterval
    private let displacedView: UIView
    var headerView: UIView?
    var footerView: UIView?
    var closeView: UIView?
    var completion: (() -> Void)?
    
    init(duration: NSTimeInterval, displacedView: UIView) {
        
        self.duration = duration
        self.displacedView = displacedView
    }
    
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return duration
    }
    
    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        
        //get the temporary container view that facilitates all the animations
        let transitionContainerView = transitionContext.containerView()! //Apple, Apple..
        
        //get the target controller's root view and add it to the scene
        let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
        transitionContainerView.addSubview(toViewController.view)
        
        //make it align with scene geometry
        toViewController.view.frame = UIScreen.mainScreen().bounds
        
        //prepare transition of background from transparent to full black
        toViewController.view.backgroundColor = UIColor.blackColor()
        toViewController.view.alpha = 0.0
        
        if isPortraitOnly() {
            toViewController.view.transform = rotationTransform()
            toViewController.view.bounds = rotationAdjustedBounds()
        }
        
        //make a screenshot of displaced view so we can create our own animated view
        let screenshot = screenshotFromView(displacedView)
        
        //make the original displacedView hidden, we can give an illusion it is moving away from its parent view
        displacedView.hidden = true
        
        //hide the gallery views
        headerView?.alpha = 0.0
        footerView?.alpha = 0.0
        closeView?.alpha = 0.0
        
        //translate coordinates of displaced view into our coordinate system (which is now the transition container view) so that we match the animation start position on device screen level
        let origin = transitionContainerView.convertPoint(CGPoint.zero, fromView: displacedView)
        
        //create UIImageView with screenshot
        let animatedImageView = UIImageView()
        animatedImageView.bounds = displacedView.bounds
        animatedImageView.frame.origin = origin
        animatedImageView.image = screenshot
        
        //put it into the container
        transitionContainerView.addSubview(animatedImageView)
        
        UIView.animateWithDuration(self.duration, animations: { () -> Void in
            
            if isPortraitOnly() == true {
                animatedImageView.transform = rotationTransform()
            }
                //animate it into the center (with optionaly rotating) - that basically includes changing the size and position
            
{'fraction_non_alphanumeric': 0.06306306306306306, 'fraction_numerical': 0.006107802717972209, 'mean_word_length': 2.513948497854077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5561962', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1487, 'n_words': 486}