Как обновить ContentMode UIImageView? - PullRequest
1 голос
/ 03 июня 2010

при первоначальном UIImageView я установил его на

mCurrentImageView.contentMode = UIViewContentModeLeft;

, поэтому, если устройство вращается, я изменю contentMode. но это не имело никакого эффекта. как я могу это исправить?

if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight) {
        mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit;
    }

1 Ответ

3 голосов
/ 03 июня 2010

[UIDevice ориентация] не возвращает эти идентификаторы для ориентации. Из документации это сообщение вернет следующее:

typedef enum {
   UIDeviceOrientationUnknown,
   UIDeviceOrientationPortrait,
   UIDeviceOrientationPortraitUpsideDown,
   UIDeviceOrientationLandscapeLeft,
   UIDeviceOrientationLandscapeRight,
   UIDeviceOrientationFaceUp,
   UIDeviceOrientationFaceDown
} UIDeviceOrientation;

Чтобы изменить режим содержимого, вы должны сделать что-то в коде контроллера представления в сообщении willRotate:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...