[英]Error to present view controller centered in iPad iOS 6
在iOS 5中,它運行正常:
PinRequiredViewController *pinView = [[PinRequiredViewController alloc]initWithNibName:@"PinRequiredView" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pinView];
// show the navigation controller modally
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalInPopover = NO;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:navController animated:YES completion:nil];
navController.view.superview.frame = CGRectMake(0, 0, 250, 250);
navController.view.superview.center = self.view.window.center;
但是在iOS6中工作不正常,視圖不會在屏幕中保持居中,包括縱向和橫向。 有解決方案嗎
謝謝!! :)
我認為如果您刪除UIModalTransitionStyleFlipHorizontal
過渡樣式並使用其他過渡樣式之一,它將起作用。
好像它是UIModalTransitionStyleFlipHorizontal
的一個錯誤。
在presentViewController中使用completion:
[self presentViewController:navController animated:YES completion:^{
navController.view.superview.bounds = CGRectMake(0, 0, 250, 250);}];
這將使它與UIModalTransitionStyleFlipHorizontal
一起UIModalTransitionStyleFlipHorizontal
。
問題是你可以將superview的框架設置為你想要的任何東西,但不會改變原點。 這就是為什么它不能保持中心的原因。
看起來Apple在iOS6中故意限制了這一點
在我對UIModalTransitionStyleFlipHorizontal的理解中,唯一的出路是先顯示沒有動畫的視圖,設置中心點,然后在下一行中解除它,然后再次顯示動畫:是。 如下.....
[self presentViewController:navController animated:NO completion:nil];
CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
navController.view.superview.center = centerPoint;
[navController dismissModalViewControllerAnimated:NO];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:navController animated:YES completion:nil];
我成功了以下幾點:
aboutViewController.modalPresentationStyle = UIModalPresentationFormSheet;
aboutViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
CGRect aboutSheetFrame = aboutViewController.view.frame;
[self presentViewController:aboutViewController animated:YES completion:^{
aboutViewController.view.superview.bounds = aboutSheetFrame;
}];
aboutViewController.view.superview.bounds = aboutSheetFrame;
在ios 6.1 beta 2上使用UIModalTransitionStyleFlipHorizontal
轉換仍然存在問題aboutSheetFrame
是為了避免硬編碼的大小。
只需在viewDidAppear而不是viewDidLoad中執行此操作。 你排序了!
對於iOS 7試試這個:
[self.navigationController presentViewController:navigationController animated:YES completion:^{
//Make the modal bigger than normal
navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
}];
動畫看起來很難看,所以我建議添加一個動畫來改進它:
[self.navigationController presentViewController:navigationController animated:YES completion:^{
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//Make the modal bigger than normal
navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
} completion:^(BOOL finished) {
}];
}];
還要記住,您需要在viewDidAppear中設置navigationControllers視圖的框架,以使內容的大小正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.