簡體   English   中英

更改設備方向時如何為uiimageview設置動畫

[英]How to animate uiimageview when changing device orientation

我有一個UIImageView,用於顯示我的應用程序的背景圖像,因此占用了整個屏幕,根據屏幕大小/設備(480點或568點)和方向,該圖像在4張圖像之間切換。

我一直在尋找是否有一種方法可以動畫化方向之間的圖像切換,因為當設備當前旋轉時,切換非常“嚴酷”,並簡要顯示了后面的空白。

我從google /這里找到的大多數內容都是人們問如何動畫化uiimageviews之間的變化,這不是我想要的,我只是更改了在單個uiimageview中顯示的圖像,如以下代碼片段所示:

- (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation {
if (IS_WIDESCREEN && UIInterfaceOrientationIsPortrait(orientation)) {
    self.backgroundImage.image = [UIImage imageNamed:@"iPhone5backgroundPortrait.png"];
    _backgroundImage.frame = CGRectMake(0, 0, 320, 568);
} if (IS_NOT_WIDESCREEN && UIInterfaceOrientationIsPortrait(orientation)) {
    self.backgroundImage.image = [UIImage imageNamed:@"iPhone4backgroundPortrait.png"];
    _backgroundImage.frame = CGRectMake(0, 0, 320, 480);
} if (IS_WIDESCREEN && UIInterfaceOrientationIsLandscape(orientation)) {
    self.backgroundImage.image = [UIImage imageNamed:@"iPhone5backgroundLandscape.png"];
    _backgroundImage.frame = CGRectMake(0, 0, 568, 320);
} else if (IS_NOT_WIDESCREEN && UIInterfaceOrientationIsLandscape(orientation)) {
    self.backgroundImage.image = [UIImage imageNamed:@"iPhone4backgroundLandscape.png"];
    _backgroundImage.frame = CGRectMake(0, 0, 480, 320);

我嘗試了[animateImageNamed:duration:]方法,但是旋轉設備時,背景消失了!

謝謝

您是否嘗試過更改圖像:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration

同樣,在某些時候預取圖像,以便在發生旋轉時它們已經在圖像緩存中-否則第一個圖像可能會有一點延遲。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM