我一直試圖完全在代碼中複製Apple的PhotoScroller示例應用程序,但目前爲止沒有成功。即使我在複製PhotoViewController,ImageScrollView和TileView類新項目和編程方式創建一個PhotoViewController情況下,它確實像PhotoScroller應用不太工作:完全在代碼中複製PhotoScroller
在我的複製軟件,我可以移動在PhotoScroller應用程序中,我只能向左和向右滾動圖像。
分頁滾動視圖無法正確對齊圖像居中,因此黑色填充可見並且圖像的某些部分不在屏幕上。
相反,一切工作正常,如果我還複製PhotoViewController和主窗口XIB文件,並設置主窗口作爲iPhone部署信息的主界面。所以在xib文件中必須有一些魔力,儘管它們對我來說基本上是空的。
下面是在應用程序中以編程方式創建PhotoViewController的代碼:didFinishLaunchingWithOptions:方法。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[PhotoViewController alloc] initWithNibName:@"PhotoViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
)
那麼在PhotoViewController.xib和MainWindow.xib文件中配置了什麼使一切正常工作?
要明白我的意思,請按照以下簡單步驟:
下載WWDC 2010的示例代碼。
打開磁盤映像,轉到iOS的文件夾,並提取PhotoScroller.zip。
解壓縮PhotoScroller.zip,在Xcode中打開,編譯並在模擬器中運行。
請注意,一切工作正常如預期。
現在將應用程序:didFinishLaunchingWithOptions:在AppDelegate.m中更改爲以下內容。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { PhotoViewController* vc = [[[PhotoViewController alloc] init] autorelease]; window.rootViewController = vc; [window addSubview:vc.view]; [window makeKeyAndVisible]; return YES; }
現在重建並在模擬器中重新運行。
請注意差異,圖像不居中,您可以看到黑色填充。
那麼在PhotoViewController.xib中,什麼設置使分頁UIScrollView居中放置ImageScrollViews?
不敢相信沒有人回覆這個,感謝很多老兄。救世主:D – Ben 2015-01-23 11:42:33