https://blog.csdn.net/qq_36557133/article/details/85760469

最近在做项目的时候发现资源包内的图片的方向不对,但也不想让UI切一个新图,所以需要将原有的图片改变其方向。

UIImage *backImage = [UIImage imageNamed:@"图片名字"];

//改变该图片的方向
backImage = [UIImage imageWithCGImage:backImage.CGImage
scale:backImage.scale
orientation:UIImageOrientationDown];
以下是图片方向的选择(添加了一些个人理解):

UIImageOrientationUp, // 默认方向
UIImageOrientationDown, // 让默认方向旋转180度
UIImageOrientationLeft, // 让默认方向逆时针旋转90度
UIImageOrientationRight, // 让默认方向顺时针旋转90度
UIImageOrientationUpMirrored, // 默认方向的竖线镜像
//(即以原图的左(或右)边的竖线为对称轴,对原图进行对称投影得到的镜像)
UIImageOrientationDownMirrored, // 让镜像旋转180度
UIImageOrientationLeftMirrored, // 让镜像逆时针旋转90度
UIImageOrientationRightMirrored, // 让镜像顺时针旋转90度
————————————————
版权声明:本文为CSDN博主「靠近星星的太阳」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_36557133/article/details/85760469

IOS 如何让button内的image旋转

https://blog.csdn.net/yangjinchao/article/details/51628561

2016-06-10 20:26:24 Y型树杈子 阅读数 8954
 
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。

 

//

// JCAllBuyViewController.m
  1. //

    //  JCAllBuyViewController.m

    //  09-彩票-空工程

    //

    //  Created by panba on 16-6-2.

    //  Copyright (c) 2016年 panba. All rights reserved.

    //

    #import "JCAllBuyViewController.h"

    #import "JCAllCaiZhongButton.h"

    @interface JCAllBuyViewController ()

    @property (nonatomic,assign,getter=isOpen) BOOL  open;

    @end

    @implementation JCAllBuyViewController

    - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

    // Custom initialization

    }

    return self;

    }

    - (void)viewDidLoad

    {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    //    self.title = @"合买跟单";

    //1-添加一个button

    JCAllCaiZhongButton *btn = [[JCAllCaiZhongButton alloc]init];

    btn.frame = CGRectMake(120, 0, 100, 44);

    [btn setTitle:@"全部彩种" forState:UIControlStateNormal];

    [btn setImage:[UIImage imageNamed:@"YellowDownArrow.png"] forState:UIControlStateNormal];

    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

    [self.navigationController.navigationBar addSubview:btn];

    }

    //2-设置小三角旋转的事件

    -(void)btnClicked:(UIButton *)titleBtn

    {

    if (!self.isOpen) {

    [UIView animateWithDuration:1 animations:^{

    titleBtn.imageView.transform = CGAffineTransformMakeRotation(M_PI);

    }];

    self.open = YES;

    }

    else

    {

    [UIView animateWithDuration:1 animations:^{

    titleBtn.imageView.transform = CGAffineTransformIdentity;

    }];

    self.open = NO;

    }

    }

    @end

    ————————————————

    版权声明:本文为CSDN博主「Y型树杈子」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

    原文链接:https://blog.csdn.net/yangjinchao/article/details/51628561

iOS 图片左右反转 反向

2016-03-22 13:33:58 jeffasd 阅读数 4496更多

分类专栏: iOS
 

http://blog.csdn.net/xyxjn/article/details/37902609

方法1

_imageView.transform = CGAffineTransformMakeScale(-1, 1);

弊端:和大小变化等动画不兼容

方法2

  1. //
  2. //  GYFlipLayer.h
  3. //  imageFlipDemo
  4. //
  5. //  Created by sun on 14-7-17.
  6. //  Copyright (c) 2014年 sun. All rights reserved.
  7. //
  8. #import <QuartzCore/QuartzCore.h>
  9. @interface GYFlipLayer : CALayer
  10. - (id)initWithLayer:(CALayer *)layer;
  11. @end
  1. //
  2. //  GYFlipLayer.m
  3. //  imageFlipDemo
  4. //
  5. //  Created by sun on 14-7-17.
  6. //  Copyright (c) 2014年 sun. All rights reserved.
  7. //
  8. #import "GYFlipLayer.h"
  9. @interface GYFlipLayer()
  10. @property (strong, nonatomic) CALayer *reflectedLayer;
  11. @end
  12. @implementation GYFlipLayer
  13. - (id)initWithLayer:(CALayer *)aLayer
  14. {
  15. self = [super init];
  16. if (self)
  17. {
  18. self.needsDisplayOnBoundsChange = YES;
  19. self.contentsScale = aLayer.contentsScale;
  20. _reflectedLayer = aLayer;
  21. self.name = [NSString stringWithFormat:@"reflectionLayer%@", aLayer.name];
  22. [self udpateFrame];
  23. }
  24. return self;
  25. }
  26. - (void)udpateFrame {
  27. CGRect frame = _reflectedLayer.bounds;
  28. self.frame = frame;
  29. }
  30. - (void)drawInContext:(CGContextRef)ctx
  31. {
  32. CGContextSaveGState(ctx);
  33. CGContextSetInterpolationQuality(ctx, kCGInterpolationNone);
  34. CGContextTranslateCTM(ctx, self.reflectedLayer.frame.size.width, 0);
  35. CGContextScaleCTM(ctx, -1.f, 1.f);
  36. [self.reflectedLayer renderInContext:ctx];
  37. CGContextRestoreGState(ctx);
  38. }
  39. @end

调用

  1. - (IBAction)flipImage:(id)sender {
  2. GYFlipLayer *rLayer = [[GYFlipLayer alloc] initWithLayer:_imageView.layer];
  3. [_imageView.layer addSublayer:rLayer];
  4. }

iOS-image图片旋转方向的更多相关文章

  1. iOS拍照图片旋转的问题

    很久之前,遇到了这种情况,iOS某端拍照上传到服务器,其他iOS端从服务器下载该照片展示,发现图片逆时针旋转了90度.当时百度了一下,找到一段代码修正image方向,问题解决了,但没有深入理解底层原理 ...

  2. ios中图片旋转

    @interface ViewController () { UIImageView *_imageview; BOOL flag; } @end @implementation ViewContro ...

  3. ios手机竖屏拍照图片旋转90°问题解决方法

    手机拍照会给图片添加一个Orientaion信息(即拍照方向),如下: 用ios手机拍照,系统会给图片加上一个方向的属性, ios相机默认的拍照方向是后摄Home键在右为正,前摄Home键在左为正. ...

  4. 【iOS】屏幕旋转,屏幕自适应方向变化

    1. iOS有四个方向的旋转,为了保证自己的代码能够支持旋转,我们必须首先处理一个函数: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInter ...

  5. iOS 图片旋转方法

    iOS 图片旋转方法 通过 CGImage 或 CIImage 旋转特定角度 UIImage可通过CGImage或CIImage初始化,初始化方法分别为init(cgImage: CGImage, s ...

  6. iOS开发 CGAffineTransform 让图片旋转, 旋转后获得图片旋转的角度

    1.让图片旋转 UIImageView *imageView = [[UIImageView alloc]init]; imageView.frame = CGRectMake(50, 50, 200 ...

  7. (转)如何处理iOS中照片的方向

    如何处理iOS中照片的方向 31 May 2015 • 7 min. read • Comments 使用过iPhone或者iPad的朋友在拍照时不知是否遇到过这样的问题,将设备中的照片导出到Wind ...

  8. js获取图片的EXIF,解决图片旋转问题

    相信大家在做项目的时候会遇到在canvas里加入图片时,图片发生90°,180°的旋转.当时的你肯定时懵逼的,为毛. 其实这就是图片的EXIF搞的鬼. 什么是EXIF 简单来说,Exif 信息就是由数 ...

  9. 【转】Unity3D研究院之设置自动旋转屏幕默认旋转方向

    http://www.xuanyusong.com/archives/2871 如下图所示,在处理屏幕默认旋转方向的时候可以在这里进行选择,上下左右一共是4个方向. 策划的需求是游戏采用横屏,但是要求 ...

随机推荐

  1. 【Unity|C#】基础篇(10)——泛型(Generic)/ 泛型约束条件(where)

    [学习资料] <C#图解教程>(第17章):https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu. ...

  2. IIS添加网站

    打开IIS 在网站上面点击右键进行添加网站 进入添加网站配置

  3. ubuntu18 + caffe+cpu+anaconda3

    本记录只暂时只记录一些错误. 编译错误,opencv3.2与anaconda3下的libtiff不兼容,冲突. 问题查找(查找所有的TIFF库与编译错误提示匹配/usr/lib/x86_64-linu ...

  4. Oracle 监听器 Listene

    Oracle 监听器 Listener 是一个重要的数据库服务器组件,在整个 Oracle 体系结构中,扮演着重要的作用.它负责管理 Oracle 数据库和客户端之间的通讯,它在一个特定的网卡端口(默 ...

  5. Mapper-元素和属性

    Mapper.xml文件内部的元素和属性     parameterType(输入类型) §  传递简单类型 §  使用#{}占位符,或者${}进行sql拼接, #{}括号中的值可以任意, ${}括号 ...

  6. codeforces 1283E New Year Parties (贪心)

    链接:https://codeforces.com/contest/1283/problem/E 题意: 有n个人住在一些房子里,有的人住在同一个房子里.每个人可以选择搬去他的房子左边那个房子或者右边 ...

  7. rf关键字

    1.获取字典中的key ${b} Set Variable ${a}[0][dealer_buy_price] Log ${b}   2.${b}的float类型转换string 再和后面比较 Sho ...

  8. Redis09——事务(悲观锁、乐观锁)

    事务 定义: Redis事务是一个单独的隔离操作 ①事务中所有的命令都会被序列化.按照顺序执行 ②事务在执行过程中不会被其他客户端发送来的命令请求打断 作用: 串联多个命令防止别的命令插队 multi ...

  9. python面试的100题(8)

    企业面试题 15.python新式类和经典类的区别? (在Python 2及以前的版本中,由任意内置类型派生出的类(只要一个内置类型位于类树的某个位置),都属于“新式类”,都会获得所有“新式类”的特性 ...

  10. Python(三):环境及其配置

    一,PYTHONPATH 默认的Python模块搜索路径,可以将路径指向anaconda3,需要开发者自己设置 二,PYTHONHASHSEED 如果该环境变量被设定为 random ,相当于 -R ...