Skip to content

Commit

Permalink
Fix an animation into single function
Browse files Browse the repository at this point in the history
  • Loading branch information
filmhomage committed Jun 6, 2016
1 parent f99508d commit ae40133
Showing 1 changed file with 35 additions and 49 deletions.
84 changes: 35 additions & 49 deletions SCLAlertView/SCLAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public enum SCLAlertViewStyle {

// Animation Styles
public enum SCLAnimationStyle {
case NoAnimation, TopToBottom, BottomToTop, LeftToRight, RightToLeft, Appear
case NoAnimation, TopToBottom, BottomToTop, LeftToRight, RightToLeft
}

// Action Types
Expand Down Expand Up @@ -692,66 +692,52 @@ public class SCLAlertView: UIViewController {
}

// Animate in the alert view
switch animationStyle {
self.showAnimation(animationStyle)

// Chainable objects
return SCLAlertViewResponder(alertview: self)
}

// Show animation in the alert view
private func showAnimation(animationStyle: SCLAnimationStyle = .TopToBottom, animationStartOffset: CGFloat = -400.0, boundingAnimationOffset: CGFloat = 15.0, animationDuration: NSTimeInterval = 0.2) {

let rv = UIApplication.sharedApplication().keyWindow! as UIWindow
var animationStartOrigin = self.baseView.frame.origin
var animationCenter : CGPoint = rv.center

switch animationStyle {

case .NoAnimation:
self.view.alpha = 1.0
return;

case .TopToBottom:
self.baseView.frame.origin.y = -400
UIView.animateWithDuration(0.2, animations: {
self.baseView.center.y = rv.center.y + 15
self.view.alpha = 1
}, completion: { finished in
UIView.animateWithDuration(0.2, animations: {
self.baseView.center = rv.center
})
})
animationStartOrigin = CGPoint(x: animationStartOrigin.x, y: self.baseView.frame.origin.y + animationStartOffset)
animationCenter = CGPoint(x: animationCenter.x, y: animationCenter.y + boundingAnimationOffset)

case .BottomToTop:
self.baseView.frame.origin.y = 400
UIView.animateWithDuration(0.2, animations: {
self.baseView.center.y = rv.center.y - 15
self.view.alpha = 1
}, completion: { finished in
UIView.animateWithDuration(0.2, animations: {
self.baseView.center = rv.center
})
})
animationStartOrigin = CGPoint(x: animationStartOrigin.x, y: self.baseView.frame.origin.y - animationStartOffset)
animationCenter = CGPoint(x: animationCenter.x, y: animationCenter.y - boundingAnimationOffset)

case .LeftToRight:
self.baseView.frame.origin.x = -400
UIView.animateWithDuration(0.2, animations: {
self.baseView.center.x = rv.center.x + 15
self.view.alpha = 1
}, completion: { finished in
UIView.animateWithDuration(0.2, animations: {
self.baseView.center = rv.center
})
})
animationStartOrigin = CGPoint(x: self.baseView.frame.origin.x + animationStartOffset, y: animationStartOrigin.y)
animationCenter = CGPoint(x: animationCenter.x + boundingAnimationOffset, y: animationCenter.y)

case .RightToLeft:
self.baseView.frame.origin.x = 400
UIView.animateWithDuration(0.2, animations: {
self.baseView.center.x = rv.center.x - 15
self.view.alpha = 1
}, completion: { finished in
UIView.animateWithDuration(0.2, animations: {
self.baseView.center = rv.center
})
})

case .Appear:
self.view.alpha = 0.0
UIView.animateWithDuration(0.2, animations: {
self.view.alpha = 1.0
}, completion: { finished in
})

animationStartOrigin = CGPoint(x: self.baseView.frame.origin.x - animationStartOffset, y: animationStartOrigin.y)
animationCenter = CGPoint(x: animationCenter.x - boundingAnimationOffset, y: animationCenter.y)
}

// Chainable objects
return SCLAlertViewResponder(alertview: self)

self.baseView.frame.origin = animationStartOrigin
UIView.animateWithDuration(animationDuration, animations: {
self.view.alpha = 1.0
self.baseView.center = animationCenter
}, completion: { finished in
UIView.animateWithDuration(animationDuration, animations: {
self.view.alpha = 1.0
self.baseView.center = rv.center
})
})
}

public func updateDurationStatus() {
Expand Down

0 comments on commit ae40133

Please sign in to comment.