UINavigationController中的Photoscroller

时间:2013-02-02 11:44:37

标签: ios uinavigationcontroller

我正在尝试在UINavigationController中使用此代码:

http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html

在故事板中:

  • 我在导航控制器中嵌入了PageViewController。
  • 我将Topbar更改为“NavigationBar”。
  • 我向NavigationBar添加了一个标题:“ImageView”。
  • 我将一个storyboard id添加到PageViewController和NavigationController。

在ImageViewScrollView.m中:

- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize

我更改了这一行:

_zoomView = [[UIImageView alloc] initWithFrame:(CGRect){CGPointZero, imageSize }];

通过这些:

CGPoint navPoint = CGPointMake(0, 45);
_zoomView = [[UIImageView alloc] initWithFrame:(CGRect){navPoint, imageSize}]; 

我也改变了这些行:

- (CGPoint)minimumContentOffset
{
    return CGPointZero;
}

通过这些:

- (CGPoint)minimumContentOffset
{
    CGPoint navPoint = CGPointMake(0, 45);
    return navPoint;
}

当我使用iOS模拟器时,我看不到navigationBar。替换CGPointZero是不够的。

怎么了?

1 个答案:

答案 0 :(得分:0)

我找到了一种将photoscroller放入UINavigationController的简单方法。

我刚刚在appdelegate.h中添加:

@property (nonatomic, retain) UINavigationController *navController;

并在appdelegate.m中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // kick things off by making the first page
    PhotoViewController *pageZero = [PhotoViewController photoViewControllerForPageIndex:0];
    if (pageZero != nil)
    {
        // assign the first page to the pageViewController (our rootViewController)
        UIPageViewController *pageViewController = (UIPageViewController *)self.window.rootViewController;
        pageViewController.dataSource = self;

        [pageViewController setViewControllers:@[pageZero]
                                  direction:UIPageViewControllerNavigationDirectionForward
                                   animated:NO
                                 completion:NULL];

        self.navController = [[UINavigationController alloc] initWithRootViewController:pageViewController];
        [[self window] setRootViewController:_navController];   
    }
return YES;

}