dee*_*pan 17
创建两个UIImageView frontImageView和backImageView
创建一个UIView containerView以包含UIImageView
在开头显示frontImageView.
翻转后,显示backImageView
码:
// before flip
frontImageView = [[UIImageView alloc] initWithImage:[UIImage
imageNamed:@"test.png"]];
containerView = [[UIView alloc] initWithFrame:frontImageView.bounds];
containerView.center = CGPointMake(200,200);
[self.view addSubview:containerView];
[containerView addSubview:frontImageView];
-(IBAction)flipButtonClicked:(id)sender
{
backImageView = [[UIImageView alloc] initWithImage:[UIImage
imageNamed:@"cardback.png"]];
backImageView.center = frontImageView.center;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:containerView
cache:YES];
[frontImageView removeFromSuperview];
[containerView addSubview:backImageView];
[UIView commitAnimations];
}Run Code Online (Sandbox Code Playgroud)
您应该能够垂直翻转视图:
imageView.transform = CGAffineTransformMake(
1, 0, 0, -1, 0, imageView.bounds.size.height
);
Run Code Online (Sandbox Code Playgroud)
我编辑了Sound Blasters代码以返回UIImageView.但是,此代码不允许您同时垂直和水平翻转图像.对此的修复应该相当容易.
- (UIImageView *) flipImage:(UIImageView *)originalImage Horizontal:(BOOL)flipHorizontal {
if (flipHorizontal) {
originalImage.transform = CGAffineTransformMake(originalImage.transform.a * -1, 0, 0, 1, originalImage.transform.tx, 0);
}else {
originalImage.transform = CGAffineTransformMake(1, 0, 0, originalImage.transform.d * -1, 0, originalImage.transform.ty);
}
return originalImage; }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14834 次 |
| 最近记录: |