[绘画]最近的练习,包括对大师作品的临摹和烈火后的龙女觉醒

[绘画]最近画的一些权利游戏的角色

[文章]如何用swift实现自定义页面间的切换动画

先实现页面之间切换的Controller

import UIKit

class CustomAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
        return 0.5
    }

    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)
        let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)
        let finalFrame = transitionContext.finalFrameForViewController(toViewController!)

        let containerView = transitionContext.containerView()

        let screenBounds = UIScreen.mainScreen().bounds
        toViewController?.view.frame = CGRectOffset(finalFrame, 0, screenBounds.size.height)

        let toViewView = toViewController?.view
        containerView.addSubview(toViewView!)

        //动画
        let duration = self.transitionDuration(transitionContext)

        UIView.animateWithDuration(duration, animations: {
            fromViewController?.view.alpha = 0.5
            toViewController?.view.frame = finalFrame
            }, completion: {(Bool finished) in
                fromViewController?.view.alpha = 1.0
                transitionContext.completeTransition(true)
        })

    }
}

在view controller的class里添加delegate

class FirstViewController: UIViewController,UIViewControllerTransitioningDelegate

添加一个属性

var customAnimationController:CustomAnimationController

初始化

required init(coder aDecoder: NSCoder) {
        customAnimationController = CustomAnimationController()
        super.init(coder: aDecoder)
    }

在切换页面前segue里指定delegate为self

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        //
        if segue.identifier == "ShowAuthor" {
            let toVC = segue.destinationViewController as UIViewController
            toVC.transitioningDelegate = self
        }
    }

实现delegate

//MARK: TransitionDelegate
    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return customAnimationController
    }

[文章]如何用swift实现运动视觉效果MotionEffect

适合iOS7及以上版本

    override func viewDidLoad() {
        super.viewDidLoad()
        //添加最下面一层
        let lowerBackgroundImageView = UIImageView(image: UIImage(named: "bgLower.png"))
        lowerBackgroundImageView.frame = CGRectInset(view.frame, -50.0, -50.0)
        view.addSubview(lowerBackgroundImageView)
        useMotionEffect(lowerBackgroundImageView, magnitude: 50.0)

        //添加中间一层
        let midImageView = UIImageView(image: UIImage(named: "bgMid.png"))
        view.addSubview(midImageView)

        //添加最上面一层
        let foregoundImageView = UIImageView(image: UIImage(named: "bgHeader.png"))
        foregoundImageView.center = CGPointMake(view.frame.width/2, view.frame.height/2)
        view.addSubview(foregoundImageView)
        useMotionEffect(foregoundImageView, magnitude: -20.0)
    }

    func useMotionEffect(view:UIView,magnitude:CGFloat) {
        let xMotion = UIInterpolatingMotionEffect(keyPath: "center.x", type: UIInterpolatingMotionEffectType.TiltAlongHorizontalAxis)
        xMotion.minimumRelativeValue = -magnitude
        xMotion.maximumRelativeValue = magnitude

        let yMotion = UIInterpolatingMotionEffect(keyPath: "center.y", type: UIInterpolatingMotionEffectType.TiltAlongVerticalAxis)
        yMotion.minimumRelativeValue = -magnitude
        yMotion.maximumRelativeValue = magnitude

        let group = UIMotionEffectGroup()
        group.motionEffects = [xMotion,yMotion]
        view.addMotionEffect(group)
    }

[文章]如何用Swift写UIDynamic

记录下

import UIKit

class FirstViewController: UIViewController,UICollisionBehaviorDelegate {
    var animator = UIDynamicAnimator()
    var gravity = UIGravityBehavior()
    var collision = UICollisionBehavior()
    var firstContact = false

    override func viewDidLoad() {
        super.viewDidLoad()

        let square = UIView(frame: CGRectMake(100, 100, 100, 100))
        square.backgroundColor = UIColor.grayColor()
        view.addSubview(square)

        animator = UIDynamicAnimator(referenceView: view)
        gravity = UIGravityBehavior(items: [square])
        animator.addBehavior(gravity)

        let barrier = UIView(frame: CGRectMake(0, 300, 130, 20))
        barrier.backgroundColor = UIColor.redColor()
        view.addSubview(barrier)

        collision = UICollisionBehavior(items: [square])
        collision.translatesReferenceBoundsIntoBoundary = true
        animator.addBehavior(collision)

        //添加一个碰撞体
        let rightEdge = CGPointMake(barrier.frame.origin.x + barrier.frame.size.width, barrier.frame.origin.y)
        collision.addBoundaryWithIdentifier("barrier", fromPoint: barrier.frame.origin, toPoint: rightEdge)

        collision.action = {
            println("(NSStringFromCGAffineTransform(square.transform)),(NSStringFromCGPoint(square.center))") //只要动就会触发,可以获得动的物体的位置
        }
        collision.collisionDelegate = self

        let itemBehaviour = UIDynamicItemBehavior(items: [square])
        itemBehaviour.elasticity = 0.6 //更改弹性
        animator.addBehavior(itemBehaviour)
    }

    func collisionBehavior(behavior: UICollisionBehavior, beganContactForItem item: UIDynamicItem, withBoundaryIdentifier identifier: NSCopying, atPoint p: CGPoint) {
        println("began contact") //碰撞时触发
        //每次碰撞都会变黄一下,然后又转成灰色
        let view = item as UIView
        view.backgroundColor = UIColor.yellowColor()
        UIView.animateWithDuration(0.3, animations: {
            view.backgroundColor = UIColor.grayColor()
        })

        //检测第一次碰撞,动态添加behaviors
        if !firstContact {
            firstContact = true
            //处理第一次碰撞的地方
        }

    }