问题是,当我尝试运行该应用程序,它由于冲突的NSAutoresizingMaskLayoutConstraints而崩溃.
2013-10-28 16:22:18.419 Red Event App[1658:60b] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand,refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSLayoutConstraint:0x145c1990 V:|-(20)-[UINavigationBar:0x145bf6b0] (Names: '|':UIView:0x145bf620 )>","<NSLayoutConstraint:0x145bf510 V:[UINavigationBar:0x145bf6b0]-(0)-[UIView:0x145bef70]>","<NSLayoutConstraint:0x145d0550 UIView:0x145a8c10.top == UIView:0x145bf620.top>","<NSAutoresizingMaskLayoutConstraint:0x145b3a40 h=-&- v=-&- UIView:0x145a8c10.midY == UIView:0x145bef70.midY + 56.5>","<NSAutoresizingMaskLayoutConstraint:0x145b3a70 h=-&- v=-&- UIView:0x145a8c10.height == UIView:0x145bef70.height + 113>" )
通常的治疗方法是将TranslatesAutoresizingMaskIntoConstraints设置为no.
但是,当我这样做时,UIPageViewController的子视图开始忽略PageViewController的边界,并且最终(尽可能看到)原点为(0,0).
在设置数据源(_itemViewControllers)时,我已经尝试通过手动设置框架来修复位置:
- (void)setupLeafs{ _itemViewControllers = [[NSMutableArray alloc]init]; for(NSString *pagename in _datasource){ RWNode *page = [_xml getPage:pagename]; UIViewController *viewController = [RWNavigationController getViewControllerFromDictionary:[page getDictionaryFromNode]]; viewController.view.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,self.view.frame.size.height); [_itemViewControllers addObject:viewController]; } }
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { UIViewController *nextViewController = [self getPrevIoUsLeaf:viewController]; nextViewController.view.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.size.height); return nextViewController; }
但也没有任何效果.
我需要限制我在做什么,所以坚持使用Masks不是一个选择.我想我正在寻找的是一种在UIPageViewController子项添加约束之后(通过任何进程调用viewControllerBeforeViewController)的方法.但我真的很想听到有关这个问题可以解决的任何方式.
编辑:
我发现了一个黑客来解决这个问题.我不太清楚我在这里列出的是整个解决方案,但是现在我注意到,经过一个多月修补代码.
首先,在设置pageviewcontroller的视图控制器中,我已经初始化了pageviewcontroller之后,我有以下两行
UIView *pageView = self.pageViewController.view; pageView.frame = self.view.frame;
不是我设置了[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];在这个视图控制器.
其次,在子控制器上,我检查视图是否在一个pageviewcontroller内部或外部使用.只有在viewviewcontroller中没有使用视图的时候,[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];设置在子视图上.
现在,这个工作(对我来说)在这一刻.但我真的希望一个不那么麻烦的解决方案.