我有这块代码放置在accelerometer: didAccelerate
,它改变了图像的裁剪。基本上,当你倾斜一个iPad的图像被截断(不调整),这正是我正在寻找的效果。注意:self.xPos
受Accelerometer.x位置影响。动画UIView/UIImageView的裁剪
UIImage *originalStringImage = [UIImage imageNamed:@"string.png"];
CGImageRef imageRef = CGImageCreateWithImageInRect([originalStringImage CGImage], CGRectMake(0.0f,0.0f, self.xPos+50.0f, 26.0f));
[self.stringImageView setImage:[UIImage imageWithCGImage:imageRef]];
self.stringImageView.frame = CGRectMake(10.0f, self.stringYPos, self.xPos+50.0f, 26.0f);
现在我想做同样的事情,虽然作为UIView动画。这些UIView动画参数之间的东西:
UIImageView *pageStringImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, placeString, 0.0f, 42.0f)];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelay:2.0];
[UIView setAnimationDuration:3.0];
pageStringImageView.frame = CGRectMake(10.0f, placeString, 900.0f, 42.0f);
UIImage *originalStringImage = [UIImage imageNamed:@"string.png"];
CGImageRef imageRef = CGImageCreateWithImageInRect([originalStringImage CGImage], CGRectMake(10.0f,placeString, pageStringImageView.frame.origin.x, 42.0f));
[pageStringImageView setImage:[UIImage imageWithCGImage:imageRef]];
[UIView commitAnimations];
但上述不起作用。实际上它甚至不显示图像。我相信这里的主要困难是在UIView动画运行时动态改变图像的大小。
任何建议或问题?
你的回答非常丰富。做得好! –
此外,剪辑到界限的部分造成了差异。没有它,我无法得到它的工作:'imageview.clipsToBounds = YES' –