0

我有一个包含其他两个 UIView 的 UIView。我试图让它们在按下按钮时翻转。这是我在按钮操作中翻转它们的代码:

- (IBAction)btMapView:(id)sender
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [UIView transitionFromView:mView1 toView:m_MapView duration:3 options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];
    [UIView commitAnimations];
}

- (IBAction)btListView:(id)sender
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [UIView transitionFromView:m_MapView toView:mView1 duration:3 options:UIViewAnimationOptionTransitionFlipFromRight completion:NULL];
    [UIView commitAnimations];
}

我在 viewDidLoad 中初始化 m_MapView,如下所示:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [m_MapView setMapType:MKMapTypeHybrid];
    [m_MapView setZoomEnabled:YES];
    [m_MapView setScrollEnabled:YES];
    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
    region.center.latitude = 42.761738 ;
    region.center.longitude = -71.463180;
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;
    [m_MapView setRegion:region animated:YES];
    m_MapView.showsUserLocation = YES;
    [m_MapView setDelegate:self];

    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 42.761738;
    zoomLocation.longitude = -71.463180;

    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, .25*METERS_PER_MILE, .25*METERS_PER_MILE);
    MKCoordinateRegion adjustedRegion = [m_MapView regionThatFits:viewRegion];

    m_MapView.autoresizingMask =
    (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

    [m_MapView setRegion:adjustedRegion animated:YES];

    DisplayMap * myLoc = [[DisplayMap alloc] init];
    myLoc.title = @"myLoc";
    myLoc.subtitle = @"Main Office";
    myLoc.coordinate = region.center;
    [m_MapView addAnnotation:myLoc];
}

而我的第二个观点只是有一个标签。

当我触摸 btMapView 按钮时,翻转发生在另一个视图上,但是当我按下 btListView 按钮时它不会翻转回来。

谁能阐明我可能做错了什么?

谢谢您的帮助。

编辑:

通过将我的代码从 viewDidLoad 移动到 viewWillAppear 并将两个按钮方法更改为此:

- (IBAction)btMapView:(id)sender
{
    [UIView transitionFromView:mView1
                        toView:m_MapView
                      duration:1
                       options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionShowHideTransitionViews 
                    completion:nil];
}

- (IBAction)btListView:(id)sender
{
    [UIView transitionFromView:m_MapView
                        toView:mView1
                      duration:1
                       options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionShowHideTransitionViews 
                    completion:nil];
}
4

2 回答 2

0

在 UIButton 操作中使用以下代码,它正常工作:

    SecondView *second=[[SecondView alloc] init];
    [UIView transitionFromView:self.view toView:second.view duration:2.0 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];

这里的 SecondView 是 SecondView 的名称。

于 2012-10-17T12:06:51.950 回答
0

尝试以下操作:

- (IBAction)btMapView:(id)sender
{
    [mView1.superview addSubview: m_MapView];
    [UIView transitionFromView:mView1 toView:m_MapView duration:3 options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionShowHideTransitionViews completion: ^(BOOL finished) { [mView1 removeFromSuperview]; }];
}

- (IBAction)btListView:(id)sender
{
    [m_MapView.superview addSubview: mView1];
    [UIView transitionFromView:m_MapView toView:mView1 duration:3 options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionShowHideTransitionViews completion:^(BOOL finished) { [m_MapView removeFromSuperview]; }];
}
于 2012-10-16T17:38:17.273 回答