容器视图在UITableViewController和UIViewController之间转换,为什么边界搞砸了?

时间:2014-06-28 02:17:56

标签: ios xcode-storyboard

我正在尝试在嵌入到容器视图中的两个视图控制器之间实现翻转。在真实的应用程序中,翻转按钮在地图和列表之间交换。

在这个问题的模型中,Coffee UITableViewController被替换为Sweets UIViewController。

layout in IB

在简单的情况下工作正常,但是当我向Sweets Controller添加一个segue转到子UIViewController时,在执行以下操作后出现问题 - 翻转 - segue - Back - Flip。重复这些操作,桌面视图慢慢地从屏幕上移开。

space appears between nav bar and tableview

FlipViewController中的代码是:

@interface FlipViewController ()
@property (strong, nonatomic) UIViewController *controller1;
@property (strong, nonatomic) UIViewController *controller2;
@property (strong, nonatomic) UIViewController *currentViewController;
@end

@implementation FlipViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.controller1 = [self.childViewControllers firstObject];
    self.currentViewController = self.controller1;

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    self.controller2 = [storyboard instantiateViewControllerWithIdentifier:@"Sweets Controller"];
    [self addChildViewController:self.controller2];
}


- (IBAction)flip:(id)sender {
    if (self.currentViewController == self.controller1) {
        [self transitionFromViewController:self.controller1 toViewController:self.controller2 duration:0.3 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:^(BOOL finished) {
            [self.controller2 didMoveToParentViewController:self];
            self.currentViewController = self.controller2;
        }];
    }
    else {
        [self transitionFromViewController:self.controller2 toViewController:self.controller1 duration:0.3 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:^(BOOL finished) {
            [self.controller2 didMoveToParentViewController:self];
            self.currentViewController = self.controller1;
        }];
    }
}
@end

一些调试似乎表明UITableView的界限在返回时变得混乱。我是否遇到了AutoLayout问题,或者是我使用transitionFromViewController的方法:获取此效果的错误方法是什么?任何建议都会受到赞赏,我已经坚持这个错误太久了!?

0 个答案:

没有答案