我想翻转一个imageView(左/右),但我找不到UIView(或UIImageView)方法来做到这一点?任何想法?
谢谢!
答案 0 :(得分:16)
我认为你唯一想要的是:
的UIView的
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;
和
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
这些动画过渡只能在动画块中使用。在容器视图上设置转换,然后换出旧视图以用于新视图,然后提交动画。
像:
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:yourContainerView cache:YES];
[yourContainerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
答案 1 :(得分:0)
将您的UIIMageView放入UIView并使用此代码(来自实用程序app项目示例)
- (void)loadFlipsideViewController {
FlipsideViewController *viewController = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
self.flipsideViewController = viewController;
[viewController release];
// Set up the navigation bar
UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
aNavigationBar.barStyle = UIBarStyleBlackOpaque;
self.flipsideNavigationBar = aNavigationBar;
[aNavigationBar release];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleView)];
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Test123"];
navigationItem.rightBarButtonItem = buttonItem;
[flipsideNavigationBar pushNavigationItem:navigationItem animated:NO];
[navigationItem release];
[buttonItem release];
}
- (IBAction)toggleView {
/*
This method is called when the info or Done button is pressed.
It flips the displayed view from the main view to the flipside view and vice-versa.
*/
if (flipsideViewController == nil) {
[self loadFlipsideViewController];
}
UIView *mainView = mainViewController.view;
UIView *flipsideView = flipsideViewController.view;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
if ([mainView superview] != nil) {
[flipsideViewController viewWillAppear:YES];
[mainViewController viewWillDisappear:YES];
[mainView removeFromSuperview];
[infoButton removeFromSuperview];
[self.view addSubview:flipsideView];
[self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView];
[mainViewController viewDidDisappear:YES];
[flipsideViewController viewDidAppear:YES];
} else {
[mainViewController viewWillAppear:YES];
[flipsideViewController viewWillDisappear:YES];
[flipsideView removeFromSuperview];
[flipsideNavigationBar removeFromSuperview];
[self.view addSubview:mainView];
[self.view insertSubview:infoButton aboveSubview:mainViewController.view];
[flipsideViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
}
[UIView commitAnimations];
}
答案 2 :(得分:0)
mainView和flipToView是imageViews的对象,而containerView是UIView的对象。
下面给出了两个示例代码,用于卷曲imageView并将ImageView从左向右翻转
- (void)curlAction:(id)sender { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.75]; [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown)forView:containerView cache:YES]; if ([flipToView superview]) { [flipToView removeFromSuperview]; [containerView addSubview:mainView]; } else { [mainView removeFromSuperview]; [containerView addSubview:flipToView]; } [UIView commitAnimations]; }
并将图像从左向右移动到这里是代码
- (void)flipAction:(id)sender { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.75]; [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:containerView cache:YES]; if ([flipToView superview]) { [flipToView removeFromSuperview]; [containerView addSubview:mainView]; } else { [mainView removeFromSuperview]; [containerView addSubview:flipToView]; } [UIView commitAnimations]; }
感谢&问候
答案 3 :(得分:0)
另一个解决方案可以在repo找到,但它不涉及动画!它仅操纵图像方向以提供一些图像效果,即垂直/水平翻转并向左/向右旋转90度。