久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何通過(guò)從 Swift 中的 UIScrollView 子類(lèi)化來(lái)制作垂

How to make a vertical UITextView by subclassing it from UIScrollView in Swift?(如何通過(guò)從 Swift 中的 UIScrollView 子類(lèi)化來(lái)制作垂直 UITextView?)
本文介紹了如何通過(guò)從 Swift 中的 UIScrollView 子類(lèi)化來(lái)制作垂直 UITextView?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我是 iOS 開(kāi)發(fā)的新手,但為了開(kāi)始使用垂直蒙古文腳本制作最基本的應(yīng)用程序,我需要一個(gè)垂直的 UITextView.我還沒(méi)有找到任何其他蒙古應(yīng)用程序開(kāi)發(fā)人員共享他們的代碼,所以我正在嘗試自己制作.蒙古語(yǔ)從上到下書(shū)寫(xiě),從左到右換行,如下圖所示:

I'm new to iOS development, but in order start making even the most rudimentary apps using the vertical Mongolian script, I need to have a vertical UITextView. I haven't found any other Mongolian app developers sharing their code so I am trying to make it myself. Mongolian is written from top to bottom and lines wrap from left to right as is illustrated in the following graphic:

滾動(dòng)應(yīng)該是水平的(從左到右).

Scrolling should be horizontal (left to right).

在 previous question 我提出了一個(gè)鏡像字體以及 UITextView 的旋轉(zhuǎn)和鏡像的組合(因?yàn)檫@是我在 Android 中所做的).但是,在閱讀 this answer 并進(jìn)一步研究 iOS 的做事方式(如使用 TextKit),我想它可能最好從頭開(kāi)始創(chuàng)建像 UIVerticalTextView 這樣的東西,而不是弄亂普通的 UITextView.因?yàn)槲铱吹?UITextView 繼承自 UIScrollView,我假設(shè)我應(yīng)該繼承 UIScrollView 來(lái)制作 UIVerticalTextView.

In a previous question I proposed a combination of a mirrored font and a rotation and mirroring of the UITextView (because that is what I had done in Android). However, after reading this answer and doing further research into the iOS way of doing things (like using TextKit), I'm thinking it may be better to just create something like UIVerticalTextView from scratch rather than messing with the normal UITextView. And since I see that UITextView inheirits from UIScrollView, I assume I should subclass UIScrollView to make the UIVerticalTextView.

我上面提到的答案是 UIView 的子類(lèi),但我在獲取時(shí)遇到了很多麻煩滾動(dòng)上班.這是我想繼承 UIScrollView 的另一個(gè)原因.此外,當(dāng)方向發(fā)生變化時(shí),該解決方案不會(huì)重新排列每行中的單詞.

The answer I mentioned above subclassed UIView but I was having a lot of trouble getting scrolling to work. This is another reason I want to subclass UIScrollView. Also that solution did not relayout the words in each line when there was an orientation change.

我收集了以下部分,但我不知道如何將它們組合在一起:

I've gathered the following pieces but I'm not sure how to put them together:

  • NSTextStorage - 應(yīng)該有這沒(méi)什么不同.它只會(huì)存儲(chǔ)蒙古語(yǔ) Unicode 文本和任何樣式信息.
  • NSTextContainer - 高度并且需要切換寬度以給出垂直文本容器的大小.(無(wú)論如何,我認(rèn)為是的.除非這可以在其他地方完成.)
  • NSLayoutManager - 什么都做特別需要在這里完成還是由 UIVerticalTextView 處理?
  • UIVerticalTextView - 這將是 UIScrollView 的子類(lèi),但需要添加和/或覆蓋哪些方法?

  • NSTextStorage - There shouldn't be anything different with this. It will just store the Mongolian Unicode text and any styling information.
  • NSTextContainer - The height and the width need to be switched to give the vertical text container size. (I think so, anyway. Unless this can be done somewhere else.)
  • NSLayoutManager - Does anything special need to be done here or is that taken care of by the UIVerticalTextView?
  • UIVerticalTextView - This will be a subclass of UIScrollView but what are the methods that need to be added and/or overridden?

class UIVerticalTextView: UIScrollView {

    // Which properties to include?
    //     - TextStorage
    //     - TextContainer
    //     - LayoutManager

    // which methods to override?

    // which methods to add to give minimal functionality like UITextView?
    //     - init
    //     = text
}

這些問(wèn)題試圖將問(wèn)題分解成更小的部分:

These questions are attempts to break the problem down into smaller pieces:

  • 如何從頭開(kāi)始制作 UITextView?
  • 如何在 Swift 中使用字符串初始化 NSTextStorage

并嘗試不同的方法:

  • 旋轉(zhuǎn)視圖是否與自動(dòng)布局兼容?
  • 在 layoutSubviews 中旋轉(zhuǎn)視圖這實(shí)際上現(xiàn)在有一個(gè)可行的解決方案.但是,它基本上涉及將三個(gè)視圖堆疊在一起.我仍然希望創(chuàng)建一個(gè)使用 TextKit 的自定義 UIScrollView 子類(lèi),就像我在當(dāng)前問(wèn)題中提出的那樣.
  • Are rotated Views compatible with Auto Layout?
  • Rotating a view in layoutSubviews This actually has a working solution now. However, it basically involves stacking three views on top of each other. I would still prefer to make a custom UIScrollView subclass that uses TextKit as I have presented in my current question.

推薦答案

如果你有一個(gè)顯示文本的字體,最簡(jiǎn)單的方法是使用普通的 UITextView:

If you have a font that displays your text the easiest way would be to use the normal UITextView:

UITextView *textView = [[UITextView] alloc] init];

textView.transform = CGAffineTransformMakeRotation(-M_PI/2);

textView.text = @"YOUR TEXT HERE";

[textView setBaseWritingDirection:UITextWritingDirectionRightToLeft forRange:[textView textRangeFromPosition:[textView beginningOfDocument] toPosition:[textView endOfDocument]]];

textView 現(xiàn)在將向右滾動(dòng)而不是向下滾動(dòng),我認(rèn)為這應(yīng)該發(fā)生在蒙古語(yǔ)中?

The textView will now scroll to the right not down, I assume that is supposed to happen for mongolian?

這篇關(guān)于如何通過(guò)從 Swift 中的 UIScrollView 子類(lèi)化來(lái)制作垂直 UITextView?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設(shè)置滾動(dòng)視圖內(nèi)容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動(dòng)滾動(dòng))
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運(yùn)行時(shí),使用 iOS 6.0 SDK 并為 iOS 5 Target 構(gòu)建會(huì)導(dǎo)致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 国产成人av在线 | 91精品久久久久久久久中文字幕 | 国产亚洲成av人片在线观看桃 | 成人av播放 | 91精品久久久久久久久 | 99精品欧美一区二区三区 | 成人毛片网 | 日韩电影一区 | 日韩精品成人一区二区三区视频 | 日韩高清中文字幕 | 超碰在线人人 | 亚洲高清在线 | 免费一区在线 | 国产精品视频一二三区 | 中文字幕日本一区二区 | 亚洲国产欧美一区 | 欧美自拍另类 | 我想看国产一级毛片 | 国产99视频精品免费播放照片 | 夜夜爽99久久国产综合精品女不卡 | 久久成人免费 | 欧美视频一区二区三区 | www.4虎影院| 国产视频在线观看一区二区三区 | 91精品国产高清一区二区三区 | 黄色网址免费在线观看 | 久久一级 | 五月天国产 | 日韩国产一区二区三区 | 亚洲视频一区 | 色综合中文 | 亚洲天堂精品一区 | 久久久久国产一区二区三区不卡 | 波多野结衣电影一区 | 女同久久另类99精品国产 | 国产精品国产精品国产专区不片 | 成人深夜福利网站 | 久久精品无码一区二区三区 | 亚洲情综合五月天 | 久久久久国产 | 亚洲一区导航 |