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];
- }