self.view.transform.rotation=CGAffinetransform.rotationIdentity 为什么要这么用

5534人阅读
- (IBAction)rotationButtonPressed:(id)sender
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, M_PI_4);
- (IBAction)scaleButtonPressed:(id)sender
self.imageView.transform = CGAffineTransformScale(self.imageView.transform, 0.9, 0.9);
- (IBAction)moveButtonPressed:(id)sender
_imageView.transform = CGAffineTransformTranslate(self.imageView.transform, 0, 10);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场主题 : CGAffineTransformIdentity是什么意思
级别: 圣骑士
可可豆: 3208 CB
威望: 3206 点
在线时间: 635(时)
发自: Web Page
CGAffineTransformIdentity是什么意思&&&
技术问题发到问答:我知道,我仍旧要在论坛继续发布问题
看到有的代码这样写 .self.left.transform = CGAffineTransformI请问这句话什么意思
级别: 论坛版主
UID: 96411
发帖: 1679
可可豆: 8282 CB
威望: 8319 点
在线时间: 3876(时)
发自: Web Page
回 楼主(黑暗骑士) 的帖子
相当于将view的transform重置,恢复成默认状态
减少对别人的依赖,                                   才能告别菜鸟时代。
关注本帖(如果有新回复会站内信通知您)
8*2-5 正确答案:11
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版用心创造滤镜
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
理解成一个变量的初始化,每次变换前都要置位,不然你变换用的坐标系统不是屏幕坐标系统(即绝对坐标系统),而是上一次变换后的坐标系统
阅读(1044)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'self.view.transform=CGAffineTransformIdentity 为什么要这么用?',
blogAbstract:'self.view.transform=CGAffineTransformIdentity;self.view.transform=CGAffineTransformMakeRotation(degreeToRadians(90));',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:2,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
I'm trying to find a reason why animation of UIView transform property looks different in iOS 8 than iOS 6/7.
For a simple example, prior to iOS 8:
myView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 1.57);
[UIView animateWithDuration:5 animations:^{
myView.transform = CGAffineTransformTranslate(plane.transform, 100, 0);
gives expected result, "myView" is rotated 90 degrees and moves down, but in iOS8 when translation is animated it starts at a point that I couldn't find explanation for (which breaks the animation).
Does anyone know the explanation for it? Thanks in advance!
6,40462040
CGAffineTransformIdentity behaves differently on ios7 and ios8. This has to do with auto-layout and size classes. The solution is to remove constraints that conflict with the animation on ios7.
// solve the constraint-animation problem
if(NSFoundationVersionNumber &= NSFoundationVersionNumber_iOS_7_1) {
// iOS7 remove constraints that conflict with animation
if (self.centerYAlignment != nil) {
self.view.removeConstraint(self.centerYAlignment) //is an IBOutlet
// iOS8 constraint animations are fine
I think the reason is just iOS8 bug, but I use CAAnimation instead, and it works as expected on iOS8.
I'm also experiencing the same issue with scaling. I guess it could be the same with rotation. Could you try this?
myView.transform = CGAffineTransformConcat(myView.transform , CGAffineTransformMakeRotate(1.57));
[UIView animateWithDuration:5 animations:^{
myView.transform = CGAffineTransformTranslate(plane.transform, 100, 0);
Maybe it's also necessary to use CGAffineTransformMakeTranslate and CGAffineTransformConcat that as well, I'm not sure.
The worst part about this is: You would have to do if/else on iOS versions, because this would look weird on iOS 7. I hope this is getting fixed by Apple before or with iOS 8 release.
I had problems with jerky rotation transform in iOS7 as well. Solved this by nesting my rotated view inside a container and centering the rotated view inside.
I agree with Pbk that it has to do with size classes in io8. uiviewcontrollers need to be resized with uitraitcollections depending on the device orientation. Otherwise, you get a uiviewcontroller in portrait mode, while the phone is in landscape mode, when you try to rotate it. So the correct steps are to rotate AND override uitraitcollections
This isn't entirely related, but I was struggling with CGAffineTransformScale not working at all on iOS7 in a fairly complicated animation.
It turns out my problem was iOS7 cannot calculate CGAffineTransformScale with CGAffineTransformRotate at the same time.
In iOS7, the last animation call you make is the only one that gets animated, so only the rotation was occurring.
This bug is fixed in iOS8.
My solution is to simplify my animation for iOS7, only turning on the fancy stuff in iOS8:
//Pre-animation setup:
CGFloat radians = (M_PI/180) * (-15);
//Get a human-readable number in degrees
self.badgeImage.alpha = 0;
//Start the image as invisible
self.badgeImage.transform = CGAffineTransformScale(self.badgeImage.transform, 1.5, 1.5);
//Start the image as scaled bigger than normal
if(NSFoundationVersionNumber & NSFoundationVersionNumber_iOS_7_1) {
//See below. We will not be rotating the image in iOS7
self.badgeImage.transform = CGAffineTransformRotate(self.badgeImage.transform, radians);
//Rotate the image if iOS8
//Animation Pieces:
[UIView animateWithDuration: 0.5
animations:^{
self.badgeImage.alpha = 1.0f; //Return image to opaque
completion:NULL];
//Scale with bounce
[UIView animateWithDuration: 1.1
usingSpringWithDamping:0.3
//Not as good as Android's bounce interpolator, but I'll take it
initialSpringVelocity:-1.0f //A negative velocity here makes the animation appear more like gravity than spring
animations:^{
self.badgeImage.transform = CGAffineTransformScale(self.badgeImage.transform, 0.67, 0.67);
//Return image to its original size. These arguments are relative to its current scale.
completion:NULL];
//Rotation
if(NSFoundationVersionNumber & NSFoundationVersionNumber_iOS_7_1) { //This second animation call negates the first one on iOS7, so remove it.
[UIView animateWithDuration: 0.9
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.badgeImage.transform = CGAffineTransformRotate(self.badgeImage.transform, (radians * -1)); //Rotate the image back to its original orientation if iOS8
completion:NULL];
Of course, you can still combine multiple effects in iOS7 if you use the confusingly-named CGAffineTransformMakeScale() function.
For instance, in the pre-animation setup, you can set both a rotation AND a scale, then set call CGAffineTransformMakeScale(1,1) to reset the image to its original metrics (MakeScale's arguments are specific, not relative - even more confusing!).
This isn't always preferable, such as my example above where "bouncing" the animation would also bounce the rotation.
2,25773678
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enablediOS 问题:怎么设置让一张图片(正方形图片)按照一个点(左上角的点吧)进行缩放,下边的代码怎么写?那几个0该怎么写啊?
CGAffineTransform transform =CGAffineTransformMake(0, 0, 0, 0, 0, 0);
CGAffineTransform rotation = CGAffineTransformScale(transform, 2, 2);
[imageView setTransform:rotation];
怎么设置让一张图片(正方形图片)按照一个点(左上角的点吧)进行缩放,下边的代码怎么写?那几个0该怎么写啊?
CGAffineTransform transform =CGAffineTransformMake(0, 0, 0, 0, 0, 0);
CGAffineTransform rotation = CGAffineTransformScale(transform, 2, 2);
[imageView setTransform:rotation];
共有 2 个回答
[imageView.layer setAnchorPoint:CGPointMake(0.5, 0.5)]; 默认是 (0.5, 0.5)
设置它的锚点位置, 左下角是 (0 ,0)
右上角是 (1, 1)
左上角是 (0, 1)
锚点就是固定不动的一个点,旋转和缩放,都是以它为中心点的.
登录后方可回复
- (void) handlePinch:(UIPinchGestureRecognizer*) recognizer
NSLog(@"捏合, %f", recognizer.scale);
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.view.frame = CGRectMake(0, 50, recognizer.view.frame.size.width, recognizer.view.frame.size.height);
recognizer.scale = 1;
frame重新设置下起始点即可。
登录后方可回复
登录后方可回答
耗时 0.0671 秒

我要回帖

更多关于 transform 的文章

 

随机推荐