CATransform3D的m34使用

CATransform3D的m34使用

 

效果图

 

源码

//
//  ViewController.m
//  StarWars
//
//  Created by YouXianMing on 15/11/3.
//  Copyright  2015年 YouXianMing. All rights reserved.
//

#import "ViewController.h"
#import "UIView+SetRect.h"

#define DEGREE(d) ((d) * M_PI / 180.0f)

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor blackColor];

    // label
    UILabel *label      = [[UILabel alloc] initWithFrame:self.view.bounds];
    label.numberOfLines = 0;
    label.textColor = [UIColor yellowColor];
    label.text          = @"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStar Wars\nAn article (abbreviated art) is a word (or prefix or suffix) that is used with a noun to indicate the type of reference being made by the noun. Articles specify grammatical definiteness of the noun, in some languages extending to volume or numerical scope. The articles in the English language are the and a/an, and (in certain contexts) some. 'An' and 'a' are modern forms of the Old English 'an', which in Anglian dialects was the number 'one' (compare 'on', in Saxon dialects) and survived into Modern Scots as the number 'ane'. Both 'on' (respelled 'one' by the Normans) and 'an' survived into Modern English, with 'one' used as the number and 'an' ('a', before nouns that begin with a consonant sound) as an indefinite article.\nTraditionally in English, an article is usually considered to be a type of adjective. In some languages, articles are a special part of speech, which cannot easily be combined with other parts of speech. It is also possible for articles to be part of another part of speech category such as a determiner, an English part of speech category that combines articles and demonstratives (such as 'this' and 'that').";
    [label sizeToFit];

    // scrollView
    UIScrollView *scrollView   = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    scrollView.backgroundColor = [UIColor blackColor];
    scrollView.contentSize     = CGSizeMake(self.view.width, label.height + self.view.height + 20);
    [self.view addSubview:scrollView];
    [scrollView addSubview:label];

    // CATransform3D
    CATransform3D plane_3D     = CATransform3DIdentity;
    plane_3D.m34               = 1.0/ -500;
    plane_3D                   = CATransform3DRotate(plane_3D, DEGREE(30), 1, 0, 0);
    scrollView.layer.transform = plane_3D;

    // animation
    [UIView animateWithDuration:30 animations:^{

        scrollView.contentOffset = CGPointMake(0, label.height + self.view.height + 20);
    }];
}

@end
//
//  UIView+SetRect.h
//  StarWars
//
//  Created by YouXianMing on 15/11/3.
//  Copyright  2015年 YouXianMing. All rights reserved.
//

#import "UIView+SetRect.h"

@implementation UIView (SetRect)

#pragma mark Frame

- (CGPoint)viewOrigin
{
    return self.frame.origin;
}

- (void)setViewOrigin:(CGPoint)newOrigin
{
    CGRect newFrame = self.frame;
    newFrame.origin = newOrigin;
    self.frame = newFrame;
}

- (CGSize)viewSize
{
    return self.frame.size;
}

- (void)setViewSize:(CGSize)newSize
{
    CGRect newFrame = self.frame;
    newFrame.size = newSize;
    self.frame = newFrame;
}

#pragma mark Frame Origin

- (CGFloat)x
{
    return self.frame.origin.x;
}

- (void)setX:(CGFloat)newX
{
    CGRect newFrame = self.frame;
    newFrame.origin.x = newX;
    self.frame = newFrame;
}

- (CGFloat)y
{
    return self.frame.origin.y;
}

- (void)setY:(CGFloat)newY
{
    CGRect newFrame = self.frame;
    newFrame.origin.y = newY;
    self.frame = newFrame;
}

#pragma mark Frame Size

- (CGFloat)height
{
    return self.frame.size.height;
}

- (void)setHeight:(CGFloat)newHeight
{
    CGRect newFrame = self.frame;
    newFrame.size.height = newHeight;
    self.frame = newFrame;
}

- (CGFloat)width
{
    return self.frame.size.width;
}

- (void)setWidth:(CGFloat)newWidth
{
    CGRect newFrame = self.frame;
    newFrame.size.width = newWidth;
    self.frame = newFrame;
}

#pragma mark Frame Borders

- (CGFloat)left
{
    return self.x;
}

- (void)setLeft:(CGFloat)left
{
    self.x = left;
}

- (CGFloat)right
{
    return self.frame.origin.x + self.frame.size.width;
}

- (void)setRight:(CGFloat)right
{
    self.x = right - self.width;
}

- (CGFloat)top
{
    return self.y;
}

- (void)setTop:(CGFloat)top
{
    self.y = top;
}

- (CGFloat)bottom
{
    return self.frame.origin.y + self.frame.size.height;
}

- (void)setBottom:(CGFloat)bottom
{
    self.y = bottom - self.height;
}

#pragma mark Center Point

#if !IS_IOS_DEVICE
- (CGPoint)center
{
    return CGPointMake(self.left + self.middleX, self.top + self.middleY);
}

- (void)setCenter:(CGPoint)newCenter
{
    self.left = newCenter.x - self.middleX;
    self.top = newCenter.y - self.middleY;
}
#endif

- (CGFloat)centerX
{
    return self.center.x;
}

- (void)setCenterX:(CGFloat)newCenterX
{
    self.center = CGPointMake(newCenterX, self.center.y);
}

- (CGFloat)centerY
{
    return self.center.y;
}

- (void)setCenterY:(CGFloat)newCenterY
{
    self.center = CGPointMake(self.center.x, newCenterY);
}

#pragma mark Middle Point

- (CGPoint)middlePoint
{
    return CGPointMake(self.middleX, self.middleY);
}

- (CGFloat)middleX
{
    return self.width / 2;
}

- (CGFloat)middleY
{
    return self.height / 2;
}

@end
//
//  UIView+SetRect.m
//  StarWars
//
//  Created by YouXianMing on 15/11/3.
//  Copyright  2015年 YouXianMing. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIView (SetRect)

// Frame
@property (nonatomic) CGPoint viewOrigin;
@property (nonatomic) CGSize  viewSize;

// Frame Origin
@property (nonatomic) CGFloat x;
@property (nonatomic) CGFloat y;

// Frame Size
@property (nonatomic) CGFloat width;
@property (nonatomic) CGFloat height;

// Frame Borders
@property (nonatomic) CGFloat top;
@property (nonatomic) CGFloat left;
@property (nonatomic) CGFloat bottom;
@property (nonatomic) CGFloat right;

// Center Point
#if !IS_IOS_DEVICE
@property (nonatomic) CGPoint center;
#endif
@property (nonatomic) CGFloat centerX;
@property (nonatomic) CGFloat centerY;

// Middle Point
@property (nonatomic, readonly) CGPoint middlePoint;
@property (nonatomic, readonly) CGFloat middleX;
@property (nonatomic, readonly) CGFloat middleY;
@end

说明

时间: 2024-11-18 16:46:31

CATransform3D的m34使用的相关文章

CATransform3D的m34值动画

CATransform3D的m34值动画   效果   源码 https://github.com/YouXianMing/Animations // // CATransform3DM34Controller.m // Animations // // Created by YouXianMing on 16/1/9. // Copyright 2016年 YouXianMing. All rights reserved. // #import "CATransform3DM34Control

iOS开发CoreAnimation解读之六——CATransform3D变换的应用

iOS开发CoreAnimation解读之五--CATransform3D变换的应用 一.引言         CATransform3D定义了一个变化矩阵,通过对矩阵参数的设置,我们可以改变layer的一些属性,这个属性的改变,可以产生动画的效果.首先,CATransform3D定义了一个4*4的矩阵,如下: ? 1 2 3 4 5 6 7 struct CATransform3D {   CGFloat m11, m12, m13, m14;   CGFloat m21, m22, m23,

关于CATransform3D矩阵变换的简单解析

关于CATransform3D矩阵变换的简单解析 效果图:   我能能够用上的CATransform3D其实很简单,并不复杂. CATransform3D有着4种东西我们可以设置.   1. 透视效果(由m34的值决定) 2. 位移变换(主要是x,y方向) 3. 缩放变换 4. 空间旋转   源码: // // RootViewController.m // // Copyright (c) 2014年 Y.X. All rights reserved. // #import "RootView

CATransform3D

目录[-] iOS开发CoreAnimation解读之五--CATransform3D变换的应用 一.引言 二.CATransform3D中的属性和方法 1.平移变换 2.缩放变换 3.旋转变换 4.旋转翻转变换 5.CATransform3D与CGAffineTransform的转换 iOS开发CoreAnimation解读--CATransform3D变换的应用 一.引言         CATransform3D定义了一个变化矩阵,通过对矩阵参数的设置,我们可以改变layer的一些属性,这

详解iOS的Core Animation框架中的CATransform3D图形变换_IOS

一.矩阵坐标CATransform3D定义了一个变化矩阵,通过对矩阵参数的设置,我们可以改变layer的一些属性,这个属性的改变,可以产生动画的效果.CATransform3D CATransform3DMakeTranslation (CGFloat tx, CGFloat ty, CGFloat tz)tx:X轴偏移位置,往下为正数. ty:Y轴偏移位置,往右为正数. tz:Z轴偏移位置,往外为正数. 例: 如果有2个图层,一个是绿色的,一个是红色的.先加载绿色,后加载红色. tx,ty的左

CollectionView旋转水平卡片布局

概述 UICollectionView真的好强大,今天我们来研究一下这种很常见的卡片动画效果是如何实现了.本篇不能太深入地讲解,因为笔者也是刚刚摸索出点眉目,但是并没有深刻地理解.如果在讲解过程中,出现不对的地方,请及时反馈. 效果图 重写API 1 2 3 4 5 6 7 8 9 10 11 12   // 我们必须重写此方法,指定布局大小 // 每次layout invalidated或者重新query布局信息时,会调用 - (void)prepareLayout;   // 用于决定布局信

UIView相关方法

 [self.view insertSubview:girlView belowSubview:bottomView];//把girlView插入到bottomView后面  [self.view insertSubview:girlView aboveSubview:bottomView];//把girlView插入到bottomView前面  [self.view insertSubview:girlView atIndex:0];//把girlView插入到0层  [self.view b

翻页效果

翻页效果   效果   说明 修正以前源码的不妥之处.   源码 https://github.com/YouXianMing/Animations // // PageFlipEffectController.m // Animations // // Created by YouXianMing on 16/1/6. // Copyright 2016年 YouXianMing. All rights reserved. // #import "PageFlipEffectControlle

iOS流布局UICollectionView系列六——将布局从平面应用到空间

iOS流布局UICollectionView系列六--将布局从平面应用到空间 一.引言         前面,我们将布局由线性的瀑布流布局扩展到了圆环布局,这使我们使用UICollectionView的布局思路大大迈进了一步,这次,我们玩的更加炫一些,想办法将布局应用的空间,你是否还记得,在管理布局的item的具体属性的类UICollectionViewLayoutAttributrs类中,有transform3D这个属性,通过这个属性的设置,我们真的可以在空间的坐标系中进行布局设计.iOS系统