So I am trying to create a fade in animation for a UI Image that is in a page view scroller after a button is clicked in the main view controller. This is my main storyboard.

class MainWorkoutViewController: UIViewController {
    // Outlet used in storyboard
    @IBOutlet var scrollView: UIScrollView?;

    override func viewDidLoad() {
        super.viewDidLoad();


        func scrollViewDidEndDragging(MainWorkoutViewController: UIScrollView,
            withVelocity: CGPoint,
            targetContentOffset : UnsafeMutablePointer<CGPoint>){

        }

        // 1) Create the three views used in the swipe container view
        var AVc :AViewController =  AViewController(nibName: "AViewController", bundle: nil);
        var BVc :BViewController =  BViewController(nibName: "BViewController", bundle: nil);
        var CVc :CViewController =  CViewController(nibName: "CViewController", bundle: nil);


        // 2) Add in each view to the container view hierarchy
        //    Add them in opposite order since the view hieracrhy is a stack
        self.addChildViewController(CVc);
        self.scrollView!.addSubview(CVc.view);
        CVc.didMoveToParentViewController(self);

        self.addChildViewController(BVc);
        self.scrollView!.addSubview(BVc.view);
        BVc.didMoveToParentViewController(self);

        self.addChildViewController(AVc);
        self.scrollView!.addSubview(AVc.view);
        AVc.didMoveToParentViewController(self);


        // 3) Set up the frames of the view controllers to align
        //    with eachother inside the container view
        var adminFrame :CGRect = BVc.view.frame;

        adminFrame.origin.x = adminFrame.width;
        AVc.view.frame = adminFrame;

        var BFrame :CGRect = AVc.view.frame;
        BFrame.origin.x = 2*BFrame.width;
        CVc.view.frame = BFrame;


        // 4) Finally set the size of the scroll view that contains the frames
        var scrollWidth: CGFloat  = 3 * self.view.frame.width
        var scrollHeight: CGFloat  = self.view.frame.size.height
        self.scrollView!.contentSize = CGSizeMake(scrollWidth, scrollHeight)
        var frame: CGRect = self.view.frame
        frame.origin.x = frame.size.width * CGFloat(1);
        frame.origin.y = 0;
        self.scrollView!.scrollRectToVisible(frame, animated: false)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func viewDidAppear(animated: Bool) {
        self.tabBarController?.selectedIndex = 2
    }
}

This is the .swift file for the first Viewcontroller that I have, which contains the image I want to fade in when the screen loads.

import UIKit

class AViewController: UIViewController {

    @IBOutlet var Background: UIImageView!

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


        UIView.animateWithDuration(1.5, animations: {
            self.Background.alpha = 1.0
        })
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

I looked around for a way to do it and that is why I have the animatedWithDuration, but instead all I am getting is the screen swiping up from the bottom of the phone. Any ideas?

Related posts

Recent Viewed