Nasıl iOS cihazın yönlendirme seziyorum? | Netgez.com
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

  • kruno j

    kruno j

    6 Mayıs 2007
  • LardTardProductions's channel

    LardTardProd

    10 NİSAN 2009
  • Rozetked | Обзоры

    Rozetked | Ð

    5 AÄžUSTOS 2011