2017-04-10 29 views
0

好的,這裏很奇怪。UITextView滾動在tvOS上翻轉

我有一個UITextView,我用一個屬性字符串填充。 TextView的不希望自身滾動,所以我必須啓用一些設置,具體爲:

override func viewDidLoad() { 
     super.viewDidLoad() 
     articleText.isUserInteractionEnabled = true 
     articleText.isSelectable = true 
     articleText.isScrollEnabled = true 
     articleText.panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouchType.indirect.rawValue)] 
     articleText.bounces = true 
     setup() 
    } 

然而,設置這些引起了滾動滾動倒置的方式相比,一切都在tvOS東西。真是離奇。滿級的代碼如下:

class ArticleViewController : UIViewController, ListingViewControllerProtocol { 

    var listing : ListingData? 

    @IBOutlet weak var articleText: UITextView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     articleText.isUserInteractionEnabled = true 
     articleText.isSelectable = true 
     articleText.isScrollEnabled = true 
     articleText.panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouchType.indirect.rawValue)] 
     articleText.bounces = true 
     setup() 
    } 

    func setup(){ 
     if let listing = self.listing { 
      APIManager.sharedInstance.getShortendArticle(url: listing.url, onCompletion: { (json) in 
       let article = ShortendArticle(fromJson: json) 
       let html = "<h1>" + article.title + "</h1>" + article.content 

       DispatchQueue.main.async(execute: { 
        let theAttributedString = try! NSAttributedString(data: html.data(using: String.Encoding.utf8, allowLossyConversion: false)!, 
                     options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], 
                     documentAttributes: nil) 
        self.articleText.attributedText = theAttributedString 
       }) 
      }) 

     } 
    } 
} 

煤礦是不一樣的相關問題,因爲我並不想從tvOSs標準

+0

[在tvOS的UICollectionView反向滾動]的可能的複製(http://stackoverflow.com/questions/34685150/invert-scrolling-in-uicollectionview-of-tvos) – Fantini

回答

0

此代碼似乎正按預期偏離,它意思是:

  • 向上輕掃手勢向下滾動文本,允許用戶繼續閱讀更多的文字。與在iOS中向上滑動類似的行爲

  • 向下滑動手勢向上滾動文本,允許回到開頭。

從tvOS人機界面指南:

Apple TV上,幾乎所有使用間接操作的手勢對象之間 移動焦點,系統滾動界面 保持關注項目可見。如果您的應用程序實施間接 操作,請確保焦點沿手勢方向移動。 如果有人在遙控器上點擊或滑動,例如,焦點 應該向右移動,這意味着內容可能向左移動。如果有人點擊或向上揮動,焦點應該向上移動。像照片 等全屏元素應該使用直接操作來代替 - 手勢移動對象,而不是焦點。例如,向右滑動應將照片從 左移到右。

https://developer.apple.com/tvos/human-interface-guidelines/user-interaction/

+0

是否有一個爲什麼collectionViews和tableViews與此不同? – spogebob92

+0

@ spogebob92編輯後添加提及到人機界面指南 –