我有一個包含兩個其他UIViews的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按鈕時它不會翻轉回來。
任何人都可以闡明我copuld做錯了什麼?
感謝您的幫助。
編輯:
得到這個移動我到viewWillAppear中的代碼從viewDidLoad中和改變兩個按鈕的方法來此工作:
- (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];
}
你不需要把transitionFromView放在begin/commitAnimations對裏面...... – Goz
所以,我確實刪除了這些行,只是離開了transitionFromView,它會翻轉一次然後翻轉回去,但是在那之後視圖是空白的。 – LilMoke