2012-09-12 200 views
6

我試圖在做翻轉動畫時更改UIPageViewController陰影顏色。 但總是隻顯示白色。 如何將翻轉側背景顏色的顏色改變爲其他顏色,如(黑色或sephia)。 iBook正在做同樣的事情。如何將陰影背景白色更改爲其他顏色

我提到,下面的圖像有白色bg,我想改變顏色。

截圖: enter image description here

+0

請找我的屏幕的連接拍 http://www.imageurlhost.com/images/xo7tttfxq3s6fdhk60s.png – Nishu

+0

看看這個:http://stackoverflow.com/questions/1079011/iphone-flipping-views-shows-a-white-background –

+0

@Ganee希望你看到了圖像附件。 http://www.imageurlhost.com/images/xo7tttfxq3s6fdhk60s.png 我正在使用UIPageViewController,因此動畫已經存在。 我需要修改背景顏色,如我在圖片中提到的。 – Nishu

回答

0
- (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx { 
UIImage *image = [images objectAtIndex:index]; 
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height); 
CGAffineTransform transform = aspectFit(imageRect, 
              CGContextGetClipBoundingBox(ctx)); 
CGContextConcatCTM(ctx, transform); 
CGContextDrawImage(ctx, imageRect, [image CGImage]); 
} 
+0

什麼會做aspectFit(imageRect, CGContextGetClipBoundingBox(CTX)) ;方法 – Nishu

-2

在可選擇的PageControl網頁的曝光度的情況下color--

UIPageControl默認不支持這一點。您必須創建自己的頁面控件並自行完成繪圖。

+0

我使用UIPageViewController而不是UIPageControl。 UIPageViewController我正在開發像iBook這樣的應用程序,而在白色陰影后面進行頁面捲曲動畫在默認情況下是存在的。我需要改變那種顏色。 – Nishu

+0

示例圖像鏈接。同時做頁面捲曲,白色bg在那裏我的應用程序支持夜間模式,所以我需要改變黑色。 http://www.techotopia.com/index.php/Image:Iphone_ios_5_uipageviewcontroller_app.jpg – Nishu

+0

http://www.imageurlhost.com/images/xo7tttfxq3s6fdhk60s.png – Nishu

7

我一直在嘗試做同樣的事情一段時間,現在我終於明白了。事實證明,你不能將背景顏色設置爲其他顏色,但是你可以提供UIPageViewController將添加到後面的另一個視圖。這就是這裏的祕密。

從蘋果公司的文檔:

Spine location        Double sided    What to pass 
UIPageViewControllerSpineLocationMid    YES    Left and Right Page. 
SpineLocationMin or SpineLocationMax    YES    Front and Back of the page. 
SpineLocationMin or SpineLocationMax    NO    Front page only. 

所以,基本上,你需要雙面屬性兩個數據源的方法設置爲yes,並提供兩個viewControllers:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController; 
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController; 

每個方法將被調用每添加一個新頁面兩次。因此,您需要提供您通常會返回的viewController,並且還需要在執行翻頁動畫時添加一個新的viewController。

這取決於你的「BackViewController」。您可以簡單地使用黑色視圖,或者如果您願意,可以截取首頁的截圖,並從中獲取鏡像圖像。

一旦你明白它是如何工作的,這並不難。我在這裏可以看到的唯一問題是,當您添加黑色視圖或具有黑色背景的任何內容時,翻頁時的陰影將變爲白色。我不知道爲什麼,但我已經看到這發生在很多不同的應用程序上,所以我猜蘋果這是正常的行爲。但它看起來很奇怪。

編輯:

我添加了一個示例代碼,以便更容易理解。 https://github.com/mattabras/DoubleSidedPageViewController

阿巴拉

+0

您可以請張貼一些代碼 - 我明白了理論,但看不到它在實踐中是如何工作的。我只有一個'頁面' - 一個雙面頁面... – daidai

+0

@ Abras-請問您可以詳細說明或者發佈一個示例嗎?我試圖實現你所說的無濟於事。謝謝。 – johnnelm9r

+1

你可以在這裏得到一個示例代碼。 https://github.com/mattabras/DoubleSidedPageViewController – Abras

相關問題