5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

スキューエフェクトをかける

Last updated at Posted at 2013-03-20

そんなになじみの無い名前だと思うのでスクショを見ていただいた方がいいと思います。

スキュー

平行四辺形に変換するわけです。
これはCATransform3DとCALayerを使って実現します。

ちなみにこの方法はUIViewに結びついたCALayerには少々使いにくいです。
(Autolayoutが有効だとエラーが出る)

以下のように行列を作成します。(CA~~~という名前で自分で定義するのは良くないかも?)

static CATransform3D CATransform3DMakeShearY(float rotation)
{
    CATransform3D shear = {
        1.0, 0.0, 0.0, 0.0,
        tanf(rotation), 1.0, 0.0, 0.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0,
    };
    return shear;
}
static CATransform3D CATransform3DMakeShearX(float rotation)
{
    CATransform3D shear = {
        1.0, tanf(rotation), 0.0, 0.0,
        0.0, 1.0, 0.0, 0.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0,
    };
    return shear;
}

これをCALayerのtransformプロパティにセットするだけです。
当然アニメーションにも利用可能です。

結局行列として表現できる変形であれば、なんでも実現できるわけなので、
標準のAPIばかりにとらわれないようにしたいですね。
機会があればパースペクティブトランスフォーム系も調べてみようとおもいます。

プロジェクト一式欲しい方はこちらから

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?