我知道如何通过在其边界内重新绘制来翻转/反射/旋转 UIImage。
- (IBAction)reflectImageView:(UIImageView)imageView {
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0.0, -imageView.bounds.size.height);
[imageView.layer renderInContext:context];
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
但是我如何为任何 UIView 创建“翻转/反射”效果,最好将其中心保持在与以前相同的位置?
谢谢!
最佳答案
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.activeView cache:YES];
// [self.activeView removeFromSuperview];
[UIView commitAnimations];
NSNumber* isReflected = [self.activeView.attributedView.attributes valueForKey:kIsReflected];
if(isReflected.boolValue)
{
self.activeView.transform = CGAffineTransformMakeScale(1,1);
[self.activeView.attributedView.attributes setValue: [NSNumber numberWithBool:NO] forKey:kIsReflected];
}else {
//do reflection
self.activeView.transform = CGAffineTransformMakeScale(-1,1);
[self.activeView.attributedView.attributes setValue: [NSNumber numberWithBool:YES] forKey:kIsReflected];
}
以上代码用于 UIView 动画。您将在其中获得各种类型动画的选项。
关于iPhone iOS 如何就地翻转/反射(reflect)任何 UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10685422/