我在UIView和UIScrollView之间进行翻转动画。翻动动画还可以。问题是我无法在两种观点之间来回翻转。检查我的代码。 我有一个名为mapViewShowing的BOOL变量来检查当前视图。
当我点击小节按钮时,我的初始视图是scrollview,视图将在地图视图和滚动视图之间翻转。 我可以在两个视图之间翻转两次。之后,翻转动画在地图视图中停止,不再翻转。 两个视图都在同一父视图下。请帮帮我。谢谢。
if(!mapViewShowing) {
[UIView transitionFromView:self.scrollView
toView:self.mapView
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
mapViewShowing = YES;
}];
} else {
[UIView transitionFromView:self.mapView
toView:self.scrollView
duration:1
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
mapViewShowing = NO;
}];
}
答案 0 :(得分:3)
这有效
在.m文件中
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[container addSubview:page1]; //You need a container view should have the same size as
//as the view that you will animate
mainViewVissible=YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)doFlip:(id)sender {
[UIView transitionFromView: (mainViewVissible ? page1:page2)
toView: (mainViewVissible ? page2 : page1)
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){
mainViewVissible=!mainViewVissible;
/* do something on animation completion */
}];
}
在.h文件中
@property (weak, nonatomic) IBOutlet UIView *container;
@property (strong, nonatomic) IBOutlet UIView *page1; //I have the view in the nib
@property (strong, nonatomic) IBOutlet UIView *page2;
@property (weak, nonatomic) IBOutlet UIButton *flipBtn;
希望这会有所帮助
答案 1 :(得分:3)
要来回转换,您应该为UIViewAnimationOptionShowHideTransitionViews
参数添加options
以转换动画。您的options
参数应为UIViewAnimationOptionShowHideTransitionViews | UIViewAnimationOptionTransitionFlipFromLeft