1

我在 UIView 和 UIScrollView 之间做一个翻转动画。翻转动画没问题。问题是我不能在两个视图之间来回翻转。检查我的代码。我有一个名为 mapViewShowing 的 BOOL 变量来检查当前视图。

当我点击条形按钮时,我的初始视图是滚动视图,视图将在地图视图和滚动视图之间翻转。我可以在两个视图之间翻转两次。之后,翻转动画在地图视图处停止并且不能再翻转。两个视图都在同一个父视图下。请帮帮我。谢谢你。

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;
                    }];
}
4

2 回答 2

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;

希望这会有所帮助

于 2013-09-27T08:54:47.457 回答
3

要来回过渡,您应该将参数添加UIViewAnimationOptionShowHideTransitionViewsoptions两个过渡动画中。你的options参数应该是UIViewAnimationOptionShowHideTransitionViews | UIViewAnimationOptionTransitionFlipFromLeft

于 2014-06-19T23:55:25.557 回答