iOS-image图片旋转方向
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
//
//
// 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
http://blog.csdn.net/xyxjn/article/details/37902609
方法1
_imageView.transform = CGAffineTransformMakeScale(-1, 1);
弊端:和大小变化等动画不兼容
方法2
- //
- // GYFlipLayer.h
- // imageFlipDemo
- //
- // Created by sun on 14-7-17.
- // Copyright (c) 2014年 sun. All rights reserved.
- //
- #import <QuartzCore/QuartzCore.h>
- @interface GYFlipLayer : CALayer
- - (id)initWithLayer:(CALayer *)layer;
- @end
- //
- // GYFlipLayer.m
- // imageFlipDemo
- //
- // Created by sun on 14-7-17.
- // Copyright (c) 2014年 sun. All rights reserved.
- //
- #import "GYFlipLayer.h"
- @interface GYFlipLayer()
- @property (strong, nonatomic) CALayer *reflectedLayer;
- @end
- @implementation GYFlipLayer
- - (id)initWithLayer:(CALayer *)aLayer
- {
- self = [super init];
- if (self)
- {
- self.needsDisplayOnBoundsChange = YES;
- self.contentsScale = aLayer.contentsScale;
- _reflectedLayer = aLayer;
- self.name = [NSString stringWithFormat:@"reflectionLayer%@", aLayer.name];
- [self udpateFrame];
- }
- return self;
- }
- - (void)udpateFrame {
- CGRect frame = _reflectedLayer.bounds;
- self.frame = frame;
- }
- - (void)drawInContext:(CGContextRef)ctx
- {
- CGContextSaveGState(ctx);
- CGContextSetInterpolationQuality(ctx, kCGInterpolationNone);
- CGContextTranslateCTM(ctx, self.reflectedLayer.frame.size.width, 0);
- CGContextScaleCTM(ctx, -1.f, 1.f);
- [self.reflectedLayer renderInContext:ctx];
- CGContextRestoreGState(ctx);
- }
- @end
调用
- - (IBAction)flipImage:(id)sender {
- GYFlipLayer *rLayer = [[GYFlipLayer alloc] initWithLayer:_imageView.layer];
- [_imageView.layer addSublayer:rLayer];
- }
iOS-image图片旋转方向的更多相关文章
- iOS拍照图片旋转的问题
很久之前,遇到了这种情况,iOS某端拍照上传到服务器,其他iOS端从服务器下载该照片展示,发现图片逆时针旋转了90度.当时百度了一下,找到一段代码修正image方向,问题解决了,但没有深入理解底层原理 ...
- ios中图片旋转
@interface ViewController () { UIImageView *_imageview; BOOL flag; } @end @implementation ViewContro ...
- ios手机竖屏拍照图片旋转90°问题解决方法
手机拍照会给图片添加一个Orientaion信息(即拍照方向),如下: 用ios手机拍照,系统会给图片加上一个方向的属性, ios相机默认的拍照方向是后摄Home键在右为正,前摄Home键在左为正. ...
- 【iOS】屏幕旋转,屏幕自适应方向变化
1. iOS有四个方向的旋转,为了保证自己的代码能够支持旋转,我们必须首先处理一个函数: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInter ...
- iOS 图片旋转方法
iOS 图片旋转方法 通过 CGImage 或 CIImage 旋转特定角度 UIImage可通过CGImage或CIImage初始化,初始化方法分别为init(cgImage: CGImage, s ...
- iOS开发 CGAffineTransform 让图片旋转, 旋转后获得图片旋转的角度
1.让图片旋转 UIImageView *imageView = [[UIImageView alloc]init]; imageView.frame = CGRectMake(50, 50, 200 ...
- (转)如何处理iOS中照片的方向
如何处理iOS中照片的方向 31 May 2015 • 7 min. read • Comments 使用过iPhone或者iPad的朋友在拍照时不知是否遇到过这样的问题,将设备中的照片导出到Wind ...
- js获取图片的EXIF,解决图片旋转问题
相信大家在做项目的时候会遇到在canvas里加入图片时,图片发生90°,180°的旋转.当时的你肯定时懵逼的,为毛. 其实这就是图片的EXIF搞的鬼. 什么是EXIF 简单来说,Exif 信息就是由数 ...
- 【转】Unity3D研究院之设置自动旋转屏幕默认旋转方向
http://www.xuanyusong.com/archives/2871 如下图所示,在处理屏幕默认旋转方向的时候可以在这里进行选择,上下左右一共是4个方向. 策划的需求是游戏采用横屏,但是要求 ...
随机推荐
- mysql 对数据的自增ID重新进行排序
创建表格时添加: create table table1(id int auto_increment primary key,...) 创建表格后添加: 删除原有主键: ALTER TABLE `ta ...
- SVN merge(合并) 时看不到以前的已经合并过的记录的标识
今天遇到这么一个事情,merge的时候以前merge过的提交记录,咩有已合并过的标识了,就是下面这样的尾巴分叉向下的箭头 通常出现这样的情况,都是工程路径不对,检查了一下,没有问题,这些meng B ...
- Java中new一个子类对象的同时并不会自动创建一个父类对象
首先重申一个概念:子类会继承父类所有非私有成员变量和方法,包括父类的构造方法 当创建一个子类对象时,首先开辟内存,然后调用类的构造函数,这里的构造函数由两部分组成,一部分是从父类继承而来的父类的构造方 ...
- Go_go build 和 go install
1.作用 go build:用于测试编译包,在项目目录下生成可执行文件(有main包). go install:主要用来生成库和工具.一是编译包文件(无main包),将编译后的包文件放到 pkg 目录 ...
- Echarts--来自官网
引入 ECharts ECharts 3 开始不再强制使用 AMD 的方式按需引入,代码里也不再内置 AMD 加载器.因此引入方式简单了很多,只需要像普通的 JavaScript 库一样用 scrip ...
- Django教程(1)
增加新的视图: 1. 在app/view.py下增加调用视图函数 def horizonG(request): return render(request, 'horizonG.html') 2. 在 ...
- XPath注入
XPath基础 XPath 即为 XML 路径语言,是一门在XML文档中查找信息的语言.XPath 基于 XML 的树状结构,有不同类型的节点,包括元素节点,属性节点和文本节点,提供在数据结构树中找寻 ...
- CentOS 7 yum配置阿里云镜像(转)
1.下载源配置 凡是下载国外的软件,比如用npm,pip,yum有时下载速度感人,最好配置国内镜像地址 yum配置阿里云镜像参考:https://blog.csdn.net/hnmpf/article ...
- JavaScript 运算,流程控制和循环
算数运算符 算术运算符 描叙 运算符 实例 加 + 10 + 20 = 30 减 - 10 – 20 = -10 乘 * 10 * 20 = 600 除 / 10 / 20 = 0.5 取余数 % 返 ...
- 我竟然把today = new Date();写在了全局变量里面
let today = new Date();应该在每次用之前重新生成新的对象,因为对于例如 today.getTime() 这种方法,取得是today对象的time,而非调用today对象取得实时时 ...