我使用以下语句来定义过渡样式
_viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
在下面的代码中,但上面的语句在以模态方式呈现时不会水平翻转
@property (nonatomic, assign) UIModalTransitionStyle *modalTransitionStyle;
@synthesize modalTransitionStyle;
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:@selector(dismissView:)] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:@selector(dismissView:)] autorelease];
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
navigationController.navigationBar.tintColor = [UIColor brownColor];
_viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:_viewController animated:YES];
任何人都知道为什么会这样。以编程方式编码everthing。
感谢您的帮助。
答案 0 :(得分:2)
这里有很多令人困惑的命名。
AFAICT,_viewController是navigationController的根视图控制器。但你引用self.viewController ...这是相同的视图控制器吗?如果是这样,为什么不一直使用访问器方法?如果没有,我不清楚你在正确的视图控制器上设置模态转换样式([self viewController]与_viewController)。
(顺便说一下,请处理格式化代码,以便在粘贴代码时以更合理的方式显示。)
答案 1 :(得分:1)
解决问题的错误方法。我建议您检查一下代码,以提高可读性和可维护性。
假设您有一个带有与按钮关联的目标操作的viewcontroller,如下所示:
...
[aButton addTarget:self
action:@selector(dismissView:)
forControlEvents:UIControlEventTouchUpInside];
...
您可以编写一个选择器方法,以便显示您的新viewcontroller,如下所示:
- (void)dismissView:(id)sender {
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:secondVC animated:YES];
[secondVC release];
}