SORU
5 NİSAN 2011, Salı


Nasıl iOS cihazın yönlendirme seziyorum?

İOS cihazın yönünü tespit etmek için nasıl bir sorum var. Değişiklik bildirimleri, geçerli yönlendirme kendini almaya ihtiyacım yok. Bu oldukça basit bir soru gibi görünüyor, ama onu kafamda bir yere oturtmaya başaramadım. Şimdiye kadar yaptıklarım aşağıda:

UIDevice *myDevice = [UIDevice currentDevice] ;
[myDevice beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation deviceOrientation = myDevice.orientation;
BOOL isCurrentlyLandscapeView = UIDeviceOrientationIsLandscape(deviceOrientation);
[myDevice endGeneratingDeviceOrientationNotifications];

Aklımda bu iş. Ben, aygıt oryantasyon bildirimleri almak için etkinleştirmek, içinde ne olduğunu sor o zaman, ama sonra çalışmıyor ve nedenini bilmiyorum.

CEVAP
12 Aralık 2012, ÇARŞAMBA


eğer UİViewController:

if (UIDeviceOrientationIsLandscape(self.interfaceOrientation))
{
    // 
}

eğer UİView:

if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
{
    //
}

UİDevice.h:

#define UIDeviceOrientationIsPortrait(orientation)  ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)
#define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)

Güncellendi:

bu kodu xxx-Öneki ekleyin.pch sonra herhangi bir yerde kullanabilirsiniz:

// check device orientation
#define dDeviceOrientation [[UIDevice currentDevice] orientation]
#define isPortrait  UIDeviceOrientationIsPortrait(dDeviceOrientation)
#define isLandscape UIDeviceOrientationIsLandscape(dDeviceOrientation)
#define isFaceUp    dDeviceOrientation == UIDeviceOrientationFaceUp   ? YES : NO
#define isFaceDown  dDeviceOrientation == UIDeviceOrientationFaceDown ? YES : NO

kullanımı:

if (isLandscape) { NSLog(@"Landscape"); }

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • adrianisen

    adrianisen

    25 Kasım 2009
  • Carlos Delgado

    Carlos Delga

    21 HAZİRAN 2011
  • eHow

    eHow

    27 NİSAN 2006