【发布时间】:2011-11-28 09:48:14
【问题描述】:
我在将新框架设置为 uiview 对象时遇到问题。 这是我的代码:
UIImageView *blockImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, [y doubleValue], self.view.frame.size.width, 86)];
[blockImage setImage:[UIImage imageNamed:@"mainscreen_block_sample.jpg"]];
[blockImage setBackgroundColor:[UIColor blackColor]];
//setting anchor point
[blockImage.layer setAnchorPoint:CGPointMake(0.5, 1.0)];
//preparing transform
float distance = 500;
CATransform3D basicTrans = CATransform3DIdentity;
basicTrans.m34 = 1.0 / -distance;
//calculating angle
double OF=oldSize/2.0-difference;
double OC=oldSize/2.0;
double angle= acosf(OF/OC);
angle=angle/2.0;
//transforming
blockImage.layer.transform = CATransform3DRotate(basicTrans, angle, 1.0f, 0.0f, 0.0f);
double newOriginY=[y doubleValue]-difference;
double newFrameHeight=blockImage.frame.size.height;
[blockImage setFrame:CGRectMake(0, newOriginY, blockImage.frame.size.width, newFrameHeight)];
NSLog(@" blockImage frame y: %g", blockImage.frame.origin.y);
NSLog(@" blockImage frame height: %g", blockImage.frame.size.height);
//adding subview
[blocks addObject:blockImage];
[self.view addSubview:[blocks objectAtIndex:([blocks count]-1)]];
//releasing memory
[blockImage release];
NSLog 输出不可取:(
新矩形的值: 新原产地:78 新帧高度:77.82
但 NSLog 不同: 块图像帧 y:85.0665 blockImage 帧高:70.7535
【问题讨论】:
标签: iphone objective-c uiview frame