我正在尝试使用UIPageViewController进行应用演练。当应用程序启动时,我将显示演练的第一页,其中包含TextView。我滚动到下一个屏幕,这一切都很好,但是当我滚动回到第一个屏幕时,文本视图的字体大小已经改变。有趣的是,当我滚动到第四个屏幕的第三个,然后回到第一个屏幕时,文本保持(或者更确切地说)其先前的大小。
我尝试使用viewWillAppear和viewDidAppeard来改变字体大小,但是你可以看到字体大小的变化,这是一种丑陋和意想不到的变化。
我在iOS 9.0.1上运行,但是这个错误使我在iOS 8.0中开始忙碌,这是我开始开发应用程序的时候。
希望有人可以帮助我。
干杯
-------------更新:审查代码:PageViewController ----------
- (void)viewDidLoad {
[super viewDidLoad];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
childViewController = (TutorialChildViewController *)[self viewControllerAtIndex:1];
tvController = (TutorialViewControllerTextViewController *)[self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:tvController];
UIPageControl *pageControl = [UIPageControl appearance];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger index = 0;
if ([viewController isKindOfClass:[TutorialChildViewController class]]) {
index = [(TutorialChildViewController *)viewController indexNumber];
}
else if ([viewController isKindOfClass:[TutorialTextViewController class]]) {
index = [(TutorialChildViewController *)viewController indexNumber];
}
if (index == 0) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSInteger index = 0;
if ([viewController isKindOfClass:[TutorialChildViewController class]]) {
index = [(TutorialChildViewController *)viewController indexNumber];
}
else if ([viewController isKindOfClass:[TutorialTextViewController class]]) {
index = [(TutorialTextViewController *)viewController indexNumber];
}
index++;
if (index == 6) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (UIViewController *)viewControllerAtIndex:(NSUInteger)index {
TutorialImageViewController *viewController = [[TutorialImageViewController alloc] initWithNibName:@"TutorialImageViewController" bundle:nil];
TutorialTextViewController *tvC = [[TutorialTextViewController alloc] initWithNibName:@"TutorialTextViewController" bundle:nil];
switch(index) {
case 0:
case 5: {
tvC.explanatoryText = [[UITextView alloc] init];
[tvC.explanatoryText setFont:[UIFont fontWithName:@"Helvetica Neue" size:17.0]];
tvC.indexNumber = index;
return tvC;
}
break;
case 1:
case 2:
case 3:
case 4: {
viewController.preview = [[UIImageView alloc] init];
viewController.explanatoryText = [[UITextView alloc] init];
[viewController.explanatoryText setFont:[UIFont fontWithName:@"Helvetica Neue" size:17.0]];
viewController.indexNumber = index;
return viewController;
}
break;
default:
break;
}
}
---------- CODE:ViewController与TextView ----------
-(void)viewWillAppear:(BOOL)animated {
[_explanatoryText setFont:[UIFont fontWithName:@"Helvetica Neue" size:17.0]];
[self.view addSubview:_explanatoryText];
switch (_indexNumber) {
case 0: {
[_explanatoryText setText:@"...text that resizes ...."];
break;
}
case 5:
[_explanatoryText setText:@" ... text that resizes..."];
break;
default:
break;
}
}
-(void)viewDidAppear:(BOOL)animated {
NSLog(@"viewDidAppear");
[_explanatoryText setFont:[UIFont fontWithName:@"Helvetica Neue" size:17.0]];
}
-(void)viewDidDisappear:(BOOL)animated {
[_explanatoryText setFont:[UIFont fontWithName:@"Helvetica Neue" size:17.0]];
}
-(void)viewWillDisappear:(BOOL)animated {
[_explanatoryText setFont:[UIFont fontWithName:@"Helvetica Neue" size:17.0]];
}
案例1-4使用不同的ChildViewController(TutorialImageViewController),麻烦的textview是explainText。
我还尝试使用ChildViewController的生命周期方法来强制文本保持相同的大小。
希望这有助于澄清事情