SORU
5 HAZİRAN 2014, PERŞEMBE


Uİ_USER_İNTERFACE_İDİOM ile akım aygıtı() tespit Swift

Swift UI_USER_INTERFACE_IDIOM() eşdeğer iPhone ve iPad arasında tespit nedir?

Swift derleme Use of unresolved identifier bir hata alıyorum.

CEVAP
5 HAZİRAN 2014, PERŞEMBE


Swift ile çalışırken, enum UIUserInterfaceIdiomtanımlı olarak kullanabilirsiniz:

enum UIUserInterfaceIdiom : Int {
    case Unspecified

    case Phone // iPhone and iPod touch style UI
    case Pad // iPad style UI
}

Bu gibi kullanabilirsiniz:

UIDevice.currentDevice().userInterfaceIdiom == .Pad
UIDevice.currentDevice().userInterfaceIdiom == .Phone
UIDevice.currentDevice().userInterfaceIdiom == .Unspecified

Ya da bir Switch ifadesi:

    switch UIDevice.currentDevice().userInterfaceIdiom {
    case .Phone:
        // It's an iPhone
    case .Pad:
        // It's an iPad
    case .Unspecified:
        // Uh, oh! What could it be?
    }

UI_USER_INTERFACE_IDIOM() olarak tanımlanan, Objective-C, bir makro,:

#define UI_USER_INTERFACE_IDIOM() \ ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? \ [[UIDevice currentDevice] userInterfaceIdiom] : \ UIUserInterfaceIdiomPhone)

Ayrıca, Objective-C ile çalışırken bile, UI_USER_INTERFACE_IDIOM() makro iOS 3.2 ve altında gösterirken sadece gerekli olduğunu unutmayın. İOS ve 3.2 dağıtırken, [UIDevice userInterfaceIdiom] doğrudan kullanabilirsiniz.

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Hollyscoop

    Hollyscoop

    30 Ocak 2007
  • Klemens Torggler

    Klemens Torg

    11 Mart 2008
  • Ryan Ha

    Ryan Ha

    9 NİSAN 2006