目录:

一、tableviewcell贴图

二、手势GestureRecognizer

5.1 Tap(按一下)

5.2 Swipe(轻扫一下)

5.3 pinch(捏/扩)

5.4 longPress(长按)

5.5 Pan(拖动)

5.6 Rotation(旋转)

6 transform变形

回到顶部

一、tableviewcell贴图

1.tableviewcell贴图

在storyboard中设置:

tableview的separator(分隔符)为none,既然要贴图默认分隔符就不要用了

tableviewcell的background为Clear Color,默认是白色,去掉才能看到效果

在代码中:

设置cell贴图backgroundView

也可以设置cell选中贴图selectedBackgroundView

     cell.textLabel.text = @"hello world";

     UIImage *image = [UIImage imageNamed:@"list.png"];

     UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

     cell.backgroundView = imageView;

     cell.backgroundColor = [UIColor clearColor];

     // cell.textLabel.backgroundColor = [UIColor clearColor];

     UIImage *selectedImage = [UIImage imageNamed:@"listSelected.png"];

     UIImageView *selectedImageView = [[UIImageView alloc] initWithImage:selectedImage];

     cell.selectedBackgroundView = selectedImageView;// 选中贴图

2 颜色美化

2.1 tintColor

当一个控件没有设置自己的颜色时,会使用父视图的tintColor

批量设置界面中的颜色:

将一个VC中view的tintColor设置成指定颜色,导致view下所有的子视图的tintColor变成此颜色,除非某个子视图的tintColor被单独设置过。

UIWindow如果在AppDelegate设置了window的tintColor,那么整个应用的tintColor都会被设置,除非某个子视图的tintColor被单独设置过。

self.window.tintColor = [UIColor redColor];

2.2 UIAppearance

可以针对某一种类型的控件设置颜色,以及贴图,UIView类(子类)的对象都有一个属性:appearance,这个属性是一个特殊对象,对这个对象进行美化和设置机会影响到这一类视图的样子

// 设置所有的button

    [[UIButton appearance] setTintColor:[UIColor blackColor]];

    [[UIButton appearance] setBackgroundImage:[UIImage imageNamed:@"delete_btn"] forState:UIControlStateNormal];

回到顶部

二、手势GestureRecognizer

1 基本概念

视图对照用户操作的一种判断,对用户触控屏幕的行为的一种包装

2 分类

一次性手势

Tap                  touch一下屏幕

Swipe              轻扫一下屏幕

连续性手势

LongPress     长按

Pinch               捏,扩

Pan                   拖动

rotation          旋转

3 使用手势

1> 用在视图上,视图识别用户的手势,识别成功后会触发事件

2> 如何将手势加到视图上

创建手势对象

调用视图对象的addGestureRecognizer方法

4 手势的类型

每一个手势都有自己的类,这些具体的手势类继承自UIGestureRecognizer,具体的手势类命名方式如:UIXxxxGestureRecognizer

每一个具体的手势对象都有特定的属性,用来描述手势具体的参数

回到顶部

5 具体的手势对象

5.1 Tap手势(UITapGestureRecognizer)touch一下屏幕

用法:

1> 创建手势对象

2> 修改手势相关属性

3> 加入到指定的view中

Tap手势特定的属性有:

.numberOfTapsRequired          连续按几下触发事件

.numberOfTouchesRequired    最少多少个触点(手指头)触发

locationInView 获取点击位置

 - (void)viewDidLoad

 {

     [super viewDidLoad];

     // 1创建手势

     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];

     // 2设置属性

     tap.numberOfTapsRequired = ; // 连续按几下触发事件

     tap.numberOfTouchesRequired = ; // 最少多少个触点(手指头)触发

     // 3添加到视图

     [self.view addGestureRecognizer:tap];

 }

 -(void)tap:(UITapGestureRecognizer *)sender{

     CGPoint point = [sender locationInView:self.view];

     NSLog(@"%f,%f",point.x,point.y);

 }

回到顶部

5.2 Swipe手势(UISwipeGestureRecognizer)轻扫一下屏幕

.numberOfTouchesRequired最少多少个触点(手指头)触发

.direction  扫的方向,不能左右上下都有,可以设置左右或上下,或设置一个方向

 - (void)viewDidLoad

 {

     [super viewDidLoad];

                // Do any additional setup after loading the view, typically from a nib.

     UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];

     swipe.numberOfTouchesRequired = ;

     //swipe.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;// 方向

     swipe.direction = UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp;// 方向

     [self.view addGestureRecognizer:swipe];

 }

回到顶部

5.3 pinch手势(UIPinchGestureRecognizer)捏,扩

scale:              缩放比例,初始值为1

velocity:     速度,只读

这两个属性一般不需要设置,而是用于读取

是持续性手势,最大的特点就是在手势执行期间会连续调用方法

 - (void)viewDidLoad

 {

     [super viewDidLoad];

     UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];

     [self.view addGestureRecognizer:pinch];

 }

 -(void)pinch:(UIPinchGestureRecognizer *)sender{

     NSLog(@"%lf,%lf",sender.scale,sender.velocity);// scale 缩放比例 velocity 速度

     if (sender.scale < 1.0 && sender.velocity < -5.0) {

         self.textField.hidden = YES;

     }

     if (sender.scale > 1.0 && sender.velocity > 15.0) {

         self.textField.hidden = NO;

     }

 }

回到顶部

5.4 longPress(UILongPressGestureRecognizer)长按

. minimumPressDuration 至少按下多少秒算长按,默认0.5

 - (void)viewDidLoad

 {

     [super viewDidLoad];

     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

     longPress.minimumPressDuration = 0.5; // 按下多少秒算长按,默认0.5

     [self.view addGestureRecognizer:longPress];

 }

回到顶部

5.5 Pan拖动

locationInView:UIView 来获取手势目前的位置在指定视图中的坐标,视图不同,坐标不同

经常用pan手势来移动指定的视图,移动时,所修改的是需要移动的视图的center属性

 - (void)viewDidLoad

 {

     [super viewDidLoad];

     UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];

     [self.view addGestureRecognizer:pan];

 }

 -(void)pan:(UIPanGestureRecognizer *)sender{

     CGPoint current = [sender locationInView:self.view];// 相对self.view托

     CGPoint point = [sender locationInView:self.subView];// 相对self.subView托

     NSLog(@"view(%f,%f)",current.x,current.y);

     NSLog(@"subView(%f,%f)",point.x,point.y);

     // center表示中心点处在父视图的哪个位置

     self.playerView.center = current;

     CGPoint velocity = [sender velocityInView:self.view]; // 一秒走多少个像素

     NSLog(@"velocity:%f,%f",velocity.x,velocity.y);

 }

回到顶部

5.6 Rotation(旋转)

.rotation  旋转的弧度(PI)

.velocity  旋转的速度,每秒多少弧度

 - (void)viewDidLoad

 {

     [super viewDidLoad];
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)]; [self.view addGestureRecognizer:rotation]; } -(void)rotation:(UIRotationGestureRecognizer *)sender{ // rotation 旋转的弧度(PI) velocity 旋转的速度,每秒多少弧度
NSLog(@"%f,%f",sender.rotation,sender.velocity); // 拿出来
CGAffineTransform imageTransform = self.imageView.transform; // 改一改 旋转
imageTransform = CGAffineTransformRotate(imageTransform, sender.rotation); // 放进去
self.imageView.transform = imageTransform; sender.rotation = ; // self.imageView.transform = CGAffineTransformMakeRotation(sender.rotation);// 第二次旋转从0开始 }

回到顶部

6 transform变形

6.1 概念:对一个view中transform属性的改变,改变此属性会导致发生变形,旋转、缩放、位移

6.2 本质:一个view的transform属性描述的其实是此view在父视图中的变化,这个属性内部是由一个3行3列的矩阵组成。

6.3 能改变的是:视图的 旋转角度、缩放比例、位移。

6.4 如何使用:UIView.transform

注意:在修改transform属性时,需要将autolayout关掉(imageView的第一个检查器),否则自动布局可能会影响变形

修改transform属性:

CGAffineTransformRotate(transform,rotation)在transform的基础上叠加一个rotation的旋转

CGAffineTransformScale()叠加一个scale的缩放

CGAffineTransformTranslation()叠加一个位移

拿出来,改一改,放进去。

创建transform的方法:

CGAffineTransformMakeRotation

CGAffineTransformMakeScale

CGAffineTransformMakeTranslation

每次改变scale后,需要将scale恢复成初始值1.0

pinch.scale = 1.0

每次translation后,需要将只恢复成初始值:[pan setTranslation:CGPointZero inView:self.view];

获取用户拖动的位置

[pan translationView:xx];

手势的状态:

开始状态

改变状态

结束状态

7 练习:图片查看器

1)使用代码向view中增加一个UIImageView对象,UIImageView的大小和图片本身的大小要一致

2)使用center属性将UIImageView移动到屏幕的中心

3)使用transform将UIImageView缩放到屏幕刚刚能显示下所有的内容,要求不损失宽高比,

4)对UIImageView增加rotation手势识别,支持旋转,

5)增加pinch手势,支持缩放

6)增加pan手势,支持位移动

7)增加tap手势,双击后恢复原装(第三步)

8 多手势同时触发

默认情况下,一个视图中如果有多个手势,同一时刻只能触发一个,如果希望手势可以同时触发,那么手势对象就需要一个委托对象回答问题:两个手势对象是否可以一起触发

1> 让当前controller遵守协议UIGestureRecognizerDelegate协议

2> 实现方法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

3> 将当前对象设置为各手势对象的委托

作业:

做一个视图类MXMessage,这个类的一个对象其实是一个聊天气泡,

MXMessageView:

-message:NSString

-formMe:BOOL

private:

-messageLabel:UILabel

-messagePopImageView:UIImageView

显示:

if(self.fromMe){

蓝色泡泡右上角,文字颜色是白色,大小根据字符串计算

}else{

灰色的泡泡,文字原色是深灰色,大小根据字符串计算

}

注意:

storyboard

一定是被storyboard创建

self.storyboard intina...创建VC

prepareSegue跳转前调用

13-UIKit(tableviewcell贴图、手势GestureRecognizer、transform变形)的更多相关文章

  1. transform(变形)和transform-origin(变形原点)

    转载请说明出处,原文地址http://blog.sina.com.cn/s/blog_780a942701014xl8.html transform(变形)和transform-origin(变形原点 ...

  2. CSS transform(变形)和transform-origin(变形原点)

    transform(变形)和transform-origin(变形原点)的说明: 目前这两个属性得到了除去ie以外各个主流浏览器webkit,firefox,opera的支持,属性名分别为 -webk ...

  3. CSS3 Transform变形理解与应用

    CSS3 Transform变形理解与应用 Transform:对元素进行变形:Transition:对元素某个属性或多个属性的变化,进行控制(时间等),类似flash的补间动画.但只有两个关键贞.开 ...

  4. 【Unity】第13章 光照贴图和光影效果

    分类:Unity.C#.VS2015 创建日期:2016-05-19 一.简介 在Unity 5中,Lighting是—种增强场景光照和阴影效果的技术,它可以通过较少的性能消耗使静态场景看上去更真实. ...

  5. hammer.js实现背景图手势缩放调整位置

    <!DOCTYPE html> <html> <head> <script> function getxy(e){ var a=new Array() ...

  6. 程序猿的量化交易之路(13)--Cointrader类图(1)

    转载须注明出处:http://blog.csdn.net/minimicall? viewmode=contents, htpp://cloudtrader.top 今天開始正式切入到Cointrad ...

  7. CSS3中的transform变形

    在CSS3中,用Transform功能可以实现文字或图像的旋转.缩放.倾斜.移动这四种类型的变形,这四种变形分别使用rotate.scale.skew和translate这四种方法来实现.将这四种变形 ...

  8. CSS3 transform变形(3D转换)

    一.三维坐标 空间中三维坐标如下图所示: 向上为-Y,向下为+Y,向左为-X,向右为+X,向前为+Z,向后为-Z. 二.perspective(n)为 3D 转换元素定义透视视图 perspectiv ...

  9. css 动画(一)transform 变形

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 有段时间我是没理清 transform.translate.transition 和 animation之 ...

随机推荐

  1. CSS样式属性

    一.背景与前景 1.背景: 2.前景字体: (二)边界和边框 border(表格边框.样式等).margin(表外间距).padding(内容与单元格间距). margin(外边距)对自身不会有变化, ...

  2. Usaco 2.3 Zero Sums(回溯DFS)--暴搜

    Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...

  3. BZOJ 1613: [Usaco2007 Jan]Running贝茜的晨练计划( dp)

    dp乱搞即可...( 我就是这样 A 的.. 后来想改快一点..然后就WA了...不理了 ------------------------------------------------------- ...

  4. MongoDB shell常用命令

    Shell操作数据库: 1.  超级用户相关: 1. #进入数据库admin use admin 2. #增加或修改用户密码 db.addUser('name','pwd') 3. #查看用户列表 d ...

  5. 漏网之鱼--HTML&CSS

    一.HTML <meta>标签使用该标签描述网页的具体摘要信息,包括文档内容类型,字符编码信息,搜索关键字,网站提供的功能和服务的详细描述等.<meta>标签描述的内容并不显示 ...

  6. python2.7_2.2_在套接字服务器上使用ForkingMixIn

    Linux系统下才能用本程序.因为有Frok新的进程.... 代码如下: # -*- coding: utf-8 -*- import os import socket import threadin ...

  7. ubuntu ~/.bash_history

    sudo apt-get update sudo apt-get install python-pip sudo pip install Django==1.7.1 sudo apt-get inst ...

  8. [lua]笔试-组合概率

    --[[ 组合概率 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem D ...

  9. 2015暑假acm短训小结

    时间很快,短训已经结束,短短20天,心里有一些思绪想要记下. 收获: 从最近发的随笔中可以看出,做得最多的是搜索——Dfs,Bfs.对于搜索,如何描述状态,如何压缩状态,如何决定下一个结点,是否可以剪 ...

  10. Eclipse快捷键 10个最有用的快捷键(转载)

    现在很多开发人员都在用eclipse.用开发工具,就是为了方便,方便你开发你的软件,方便你管理你的工程,而开发工具提供各种功能大部分会有对应的快捷键,下面就列出了eclipse的快捷键.   Ecli ...