//
Viewcontroller.swift
Animationalert
//
Created by Su on 15/12/9.
Copyright©2015 year Tian. All rights reserved.
//
Import UIKit
Class Viewcontroller:uiviewcontroller {
Override Func Viewdidload () {
Super.viewdidload ()
Grey Masking Plate
Let Overlayview = UIView (frame:self.view.bounds)
Overlayview.backgroundcolor = Uicolor.blackcolor ()
Overlayview.alpha = 0
Join the scene
Self.view.addSubview (Overlayview)
Warning box-related code
Width of the warning box
Let Alerdimension:cgfloat = 250
Let Alertviewframe = CGRect (X:SELF.VIEW.BOUNDS.SIZE.WIDTH/2-ALERDIMENSION/2, y:self.view!. BOUNDS.SIZE.HEIGHT/2-ALERDIMENSION/2, Width:alerdimension, height:alerdimension)
Let Alertview = UIView (frame:alertviewframe)
Alertview.backgroundcolor = Uicolor (Patternimage:uiimage (named: "Alert_box")!)
Alertview.alpha = 1
Warning box Initial size is 1.2 times times
Alertview.transform = Cgaffinetransformmakescale (1.2, 1.2)
Set the fillet radius
AlertView.layer.cornerRadius = 10
Set Shadow
Color
AlertView.layer.shadowColor = Uicolor.blackcolor (). Cgcolor
Shadow Offset
AlertView.layer.shadowOffset = Cgsizemake (0, 5)
Shadow Transparency
alertView.layer.shadowOpacity = 0
Radius of the Shadow
AlertView.layer.shadowRadius = 10
Self.view.addSubview (Alertview)
Delay setting
var minseconds = 1 * Double (NSEC_PER_MSEC)
var dtime = Dispatch_time (Dispatch_time_now, Int64 (minseconds))
Dispatch_after (Dtime, Dispatch_get_main_queue ()) {(), Void in
Customize the top half of a warning box animation
Uiview.animatewithduration (0.3, delay:0, Options:UIViewAnimationOptions.CurveEaseInOut, animations: {()-Void in
Overlayview.alpha = 0.3
Alertview.alpha = 1
}, Completion:nil)
Let scale = Jnwspringanimation (keypath: "Transform.scale")
scale.damping = 14
Scale.stiffness = 14
Scale.mass = 1
Scale.fromvalue = 1.2
Scale.tovalue = 1
AlertView.layer.addAnimation (scale, ForKey:scale.keyPath)
Alertview.transform = Cgaffinetransformscale (cgaffinetransformidentity, 1, 1)
}
Minseconds = 3 * Double (NSEC_PER_MSEC)
Dtime = Dispatch_time (Dispatch_time_now, Int64 (minseconds))
Dispatch_after (Dtime, Dispatch_get_main_queue ()) {(), Void in
The lower half disappears
Uiview.animatewithduration (1, delay:0, Options:UIViewAnimationOptions.CurveEaseInOut, animations: {(), Void in
Overlayview.alpha = 0
Alertview.alpha = 0
}, Completion:nil)
Let Scaleout = Jnwspringanimation (keypath: "Tranform.scale")
scaleout.damping = 14
Scaleout.stiffness = 14
Scaleout.mass = 1
Scaleout.fromvalue = 1
Scaleout.tovalue = 0.7
AlertView.layer.addAnimation (Scaleout, ForKey:scaleOut.keyPath)
Alertview.transform = Cgaffinetransformmakescale (0.7, 0.7)
}
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
Dispose of any resources the can be recreated.
}
}
Swift Custom Bullet Box