顯示具有 介紹 標籤的文章。 顯示所有文章
顯示具有 介紹 標籤的文章。 顯示所有文章

2015年4月10日 星期五

Markdown 介紹及相關資源

簡介


這是官方網站上介紹
Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

Thus, “Markdown” is two things: (1) a plain text formatting syntax; and (2) a software tool, written in Perl, that converts the plain text formatting to HTML. See the Syntax page for details pertaining to Markdown’s formatting syntax. You can try it out, right now, using the online Dingus.

The overriding design goal for Markdown’s formatting syntax is to make it as readable as possible. The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions. While Markdown’s syntax has been influenced by several existing text-to-HTML filters, the single biggest source of inspiration for Markdown’s syntax is the format of plain text email.

OpenFoundry 上的介紹
Markdown 是一個輕量的標記語言,主要用於讓人們可以不用 HTML 複雜繁長的語法就能夠標記格式而達到管理文件的目的。Markdown 是由 John Gruber 跟 Aaron Swartz 所創造出來的。他們希望能夠讓人們可以用易讀,易寫的簡單文件格式,透過工具格式化轉成 HTML。經過多年的發展,Markdown 已經成為許多人做筆記的第一選擇了。原因除了其簡潔直觀的語法還有就是長期來慢慢累積出來的周邊工具。Markdown 已經不再僅僅只是用於標記基礎格式的語言了。圍繞著 Markdown 產生出來的工具組已經可以讓這個標記語言作到細緻的排版。已經有為數不少的人用 Markdown 來創造他們的數位著作。知名的源碼版本控制服務網站 GitHub 用 Markdown 作為他們預設支援的文本格式。其它還有許多的服務都支援 Markdown 作為他們優先支援的格式。

Markdown其實是 (1) 一種文本語法 (2) 一個轉化文件成HTML格式的軟體工具,他的工具是用Perl寫成。


教學

  1. markdowntutorial.com:這個網站透過說明跟實際操作分成 italics and bold、Headers、Links、Images、Block quotes、Lists、Paragraphs、Conclusion 八個部分學習 Markdown 的語法及其運作的原理,非常棒的教學網站。
  2. Markdown 官方語法說明 繁體中文版
  3. 简单的Markdown指南:這篇部落格寫得非常簡單一目了然
  4. 簡單易學的Markdown文字標記語法:這篇更簡單XDD


編輯器(註一)

Web
  1. Cmd Markdown:編輯閱讀器,支援即時同步預覽,區分寫作和閱讀模式,支援線上儲存,分享文稿網址。 
  2. Dillinger:一個 Markdown 的線上編輯器,可以即時顯示結果,提供即時預覽以及到 GitHub 和 Dropbox 的拓展連線。 
  3. IPython Notebook:以IPython為後台,利用瀏覽器做IDE,支援Markdown與LaTex公式。
  4. tmpvar:This is an adaption of the github markdown previewer and uses github readme styling
  5. http://jbt.github.io/markdown-editor/:Live (Github-flavored) Markdown Editor,Open Source。
  6. Markable

Desktop
  1. Mou:一個Mac OS X上的Markdown編輯器,十五美金。
  2. MacDown:OS X 上的 Markdown 開源編輯器,作者稱其深受 Mou 啟發。 
  3. WMD:a Javascript "WYSIWYM" editor for Markdown (from AttackLab) 
  4. PageDown:一個 Javascript 寫的 "WYSIWYM" Markdown編輯器 (來自 StackOverflow) 
  5. MarkdownPad:Windows,需要安装 Microsoft .NET Framework 4.0。 
  6. MarkPad
  7. Markdown textarea:GreaseMonkey 脚本,此脚本会在文本域的左下角新增一个 Markdown 按钮,输入各种包含 Markdown 的文字之后,点击它就可以把代码转化为为 HTML。
  8. ReText:Linux,Ubuntu 安裝方法参考这里


GitHub Flavored Markdown

  • GitHub uses "GitHub Flavored Markdown," or GFM, across the site--in issues, comments, and pull requests. It differs from standard Markdown (SM) in a few significant ways, and adds some additional functionality.
  • If you're not already familiar with Markdown, take a look at Markdown Basics. 
  • If you'd like to know more about features that are available in issues, comments, and pull request descriptions, such as task lists, read Writing on GitHub.
  • Mastering Markdown:這是另一份 Github 教 Markdown 的文件。


相關討論文章

为什么作家应该用 Markdown 保存自己的文稿
Markdown写作浅谈


其它

CommonMark:有人試著標準化 Markdown,這是在他們官網上寫的:「We propose a standard, unambiguous syntax specification for Markdown, along with a suite of comprehensive tests to validate Markdown implementations against this specification. We believe this is necessary, even essential, for the future of Markdown.」。當初他們好像想要用 Standard Markdown 的名字,但讓 Markdown的原創者非常 infuriating,這篇文章是他們的道歉。


註一:工具大部份都整理自台版維基百科


-------------------------------------------------這條線以下未整理QQ------------------------------------------------

Syntax Guides


Converters

The implementations above by default refer to Markdown to XHTML conversion. Converters to and from other formats are also available.
  • Markdown to LaTeX, Markdown+LaTeX to MathML, etc.
  • XHTML to Markdown:
    • html2text.py (in Python)
    • Markdownify (in PHP)
    • Make.text (a bookmarklet which converts any web page into Markdown.)
    • XHTML-to-Markdown XSLT (a stylesheet, works with XHTML only)
    • Pandoc (a Haskell library that can convert between many formats including Markdown, HTML, reStructuredText, LaTeX, MediaWiki and others)
    • html2x (web form and bookmarklet, based on Pandoc)
    • kramdown (Ruby)
  • Other formats to Markdown:
    • Pandoc (a Haskell library that can convert between many formats including Markdown, HTML, reStructuredText, LaTeX, and others)
    • odt2txt (a Python script to convert OpenDocument text files to Markdown)
    • word_markdown_macro (a Microsoft Word macro that converts some of Word’s formatting into Markdown)


Online tools (that means it works in your browser)

  • Dillinger free online markdown editor that supports syncing with Dropbox, Google Drive and Github.
  • Dingus
  • There are many of these tools so if you want to work in a browser, find the one you like best.
  • If you want to turn a website into Markdown, then its easy to do with html2text, or by using the make.text bookmarklet (also see Marky)
  • I really like using gist by github for sharing and collaborating (called forking) on documents. Here's a sample:P
  • Draft is a comprehensive online writing environment that uses Markdown. However, it requires you to create an account and is a bit confusing.


Other Software

HOWTOs

Tests

http://xbeta.org/wiki/show/Markdown
http://whatismarkdown.com

2015年4月8日 星期三

語言在地化(Localization) 相關資源整理

在地話大概分成三個部分

  1. Storyboard
  2. 程式裡的字串
  3. 圖片


網路上的教學文
Working with Localization in iOS 8 and Xcode 6
Internationalization and localization of Apps in Xcode 6 and Swift

文章
Localization Highlights from WWDC

蘋果為此還有設了一個專頁:Build Apps for the World

下面是蘋果官方整理的資源:

WWDC Session Videos

論壇


文件和範例檔
iOS
Mac


Downloads
AppleGlot and Localization Glossaries
  • AppleGlot is a tool for extracting text strings to be translated and then merging them back into the localized application environment.
  • Glossaries is the files that can be used by AppleGlot as translators to help streamline the localization process.

最後面還有提供一些第三方專門負責做翻譯的廠商,這個部分我就不轉帖了,有需要的人就點進去看吧。
不過要注意蘋果有聲明這些廠商跟蘋果一點法律關係都沒有,蘋果只是提供這些廠商的連結而已喔!

2014年10月26日 星期日

Local Notification介紹

基本設定

請求使用者運允許發送通知
從iOS 8開始,如果打完上面的程式就執行會出現類似下面這樣的錯誤碼

要把下面這段程式加上去,請求使用者允許App發送通知,我們的Local Notification才能正常運作,在iOS 8之前當然也要使用者的同意,不過可能以前是系統自動幫我們問吧,不過就像我常講的,其實我們不太需要知道以前是怎麼樣,反正現在這段程式是一定要寫就對了!

自訂特定的時間
一般fireDate的設定我們都是使用我們既有的資料或是稍微經過dateByAddingTimeInterval之類的處理,如果要完全自訂一個特定的時間的話,可以參考下面的程式碼。你會注意要我只設定了小時跟分鐘,如果想要設定通知是每天固定發出,只要設定小時跟分鐘就可以了。

alertAction
這段程式有個小問題,它可以執行,但我必須要自己去「設定」那裏把alert sytle從Banners改成Alerts,notification才會顯示成alert的形式,我目前還不知道問題出在哪裡,知道的人拜託告訴我~

icon Badge
注意第三行程式,我們也可以讀取目前的IconBadgeNumber做累加的動作

重複

使用自訂的聲音
我沒想到要使用自訂的聲音竟然這麼簡單,只要將想要播放的音檔匯入project中,再如下面的程式碼打就可以了,不過有兩點需要注意:
1音檔的長度不可以超過三十秒,要不然聲音會播不出來,我在Documentation裡沒看到這項規定,是在stackoverflow裡看到這篇回答才知道的,但我確定有這項限制,因為我之前就是卡關在這裡Orz
2音檔只有一些特定的格式可以

在通知中另外夾帶參數(一般是供其它地方的程式辨識用)

取消Local Notification
取消指定的通知
其實沒有一定要用下面的方式來尋找指定的Local Notification,也可以用其他屬性像是fireDate、alertBody...等,只要你能找到你要的特定通知就可以了。另外,雖然可以抓到自己想要的特定通知,但我試過並不能再修改其屬性。

取消全部

按下發送出來的通知後怎麼處理
當App已經沒有在運作

當App已經還在運作(可能在背景或是或是正在使用)


更深入的探討
https://www.facebook.com/groups/iostw/permalink/906779296016087/
https://www.facebook.com/groups/iostw/permalink/934380229922660/
https://www.facebook.com/photo.php?fbid=10202759629864986&set=gm.967383696622313&type=1

用Local Notification實現Alarm
要實作一個Alarm需要做到下面這幾點:
1播放音樂
2在背景執行
3定時
其實上面三點是一句話拆開來講:「在一段時間後在背景播放音樂」
我查了很多資料,發現目前Local Notification是唯一可以完全達到上面要求的方法,但那只是從技術面來看,實際使用的話會遇到兩個問題:
1.1Local Notification的聲音最長只能到三十秒,如果要做的一個鬧鐘的程式,我們絕對不可能讓他只響三十秒,當然我們可以一連排程好幾的Local Notification,可是這樣使用者打開他的iPhone的時候就是看到四五個Notification,這樣的使用者體驗非常差。
1.2我目前想到比較好的方法是:設一連串的Local Notification,只有第一個有設alertBody,後面幾個都設nil,因為我發現如果alertBody設nil,iDevice不會顯示任何東西,但音樂還是會播放。
1.3不過後來經過測試,這樣的UX爛炸了,因為一般我要用自訂的聲音,音檔一般都會像是一首歌之類的,用上面的方法,這首歌每次只會播三十秒就重新播放,越聽只讓我越煩燥而已。
2沒辦法像內建的鬧鐘可以有按鈕讓鬧鐘稍後再播放

我去網路上問,不過看起來應該是無解了Orz

2014年10月9日 星期四

@property 介紹

@property是在Objective-C 2.0(2006年)新加入的功能,目的是要簡化一個實體變數(instance variable, 簡稱ivar)設定的過程。
在沒有@property功能之前,要自己宣告setter跟getter。

各種屬性介紹

讀寫相關:
  • readwrite(default)
  • readonly

記憶體管理相關:
  • Automatic Reference Counting(ARC):這部分對初學者來說比較難懂,簡單講,絕大部分時我們會用的是strong,weak是一些比較進階的功能才會用到,所以初學者每次在設定的時候用strong就可以了。如果想要知道背後詳細的原理及解釋可以看我另外寫的這篇Automatic Reference Counting(ARC)。
    • strong:
    • weak:
  • Manual Reference Counting(MRC):這是上一代的記憶體管理方式,現在已經不用了,因為ARC遠遠比MRC好用太多了,只需要知道有這些屬性的存在就可以了,因為在網路上還是很容易找到比較舊的文章是用MRC。
    • assign(default) : 直接指派,不進行 retain
    • retain : 先 release 再 retain 新值
    • copy : 先 release 再 copy 新值

多執行緒相關:對初學者來說,這部分比較難懂,我後面打的解釋是結果論,如果想要知道兩個屬性背後實際上是怎麼回事可以看這篇atomic vs. nonatomic
  • nonatomic : 沒有要用多執行序就選這個,但不知道為什麼Apple並沒有把這個屬性設為預設,所以幾乎是每次都要加上這個屬性。
  • atomic(default) : 如果要使用多執行序就選這個。

setter/getter相關(accessors):
  • setter = setterName:重新命名setter名稱
  • getter = getterName:重新命名getter名稱,最常改的方式是在原本的名稱加「is」ex:@property (nonatomic, getter = isChosen) BOOL chosen;

@synthesize

@property DECLARES the accessors for your property, @synthesize will IMPLEMENT them.
原本是在@interface的程式
-(int) price;
-(void) setPrice: (int) p;
可以只要寫
@property int price;

在@implementation的程式從
-(int) price
{
  return price;
}

-(void) setPrice: (int) p
{
  price = p;
}
變成只要寫
@synthesize price;
Xcode 4.3 之前,每一個 @property 都要在 @implementation 加上 @synthesize 變數名稱 或 @synthesize 變數名稱 =_ 變數名稱 但 4.4 之後就自動化了,如果沒寫,就等於寫了 @synthesize 變數名稱 =_ 變數名稱,而 @synthesize 的設定,也可以改變變數的名稱,如 【@synthesize 變數名稱;】 時,變數名稱前面就不再有 underline, 有興趣的讀可以查一下 @synthesize 的功能。

2012年Objective-C加入了不少新功能,@synthesize變成預設值,現在有沒有寫@synthesize的差別只在於你取用變數的方式:
有寫@synthesize
price
沒有寫@synthesize
self.price

自訂setter/getter

但如果你要自訂自己的setter/getter的話,你就要自己寫setter/getter 函數,系統會以你自己寫的函數為主。
例如我們自訂setter:
-(void)setPrice:(int)p
{
  price = p * 2;
}
這樣的話當我們在給price值的時候,就會自動變成兩倍,也就是當我們打的程式碼是:
price = 3;
price的值實際上是6而不是3,因為3傳入時還會被乘以二。


Attribute 屬性

在2006年發佈了Objective-C 2.0後,Objective-C也可以使用「.」來存取物件的屬性
原本要設值是這樣
[b setPrice:300];
就可以寫成
b.price = 300;

不過在高見龍的部落格裡有提到點語法的一個小細節,有可能造成無窮回圈:
-(void) setPrice: (int) p
{
  self.price = p;
}
如果在自訂的setter裡使用了點語法,那就會不斷的呼叫自己(setter函數),變成無窮迴圈。


    整理來源:
    http://stackoverflow.com/questions/9162926/ios-property-declaration-clarification
    http://pydoing.blogspot.tw/2012/08/objc-property-and-synthesize.html
    http://shenfive.pixnet.net/blog/post/48054812-@property-
    http://blog.eddie.com.tw/2010/12/08/property-and-synthesize/

      2014年10月6日 星期一

      Auto Layout 介紹

      Auto Layout 是個讓界面上的物件可以依據螢幕解析度大小的不同layout到畫面上正確的位置上的技術,2011年在Cocoa中發表,在2012年隨著iOS 6發表用來取代autosizing masks (struts-and-springs model) 。Auto Layout除了解決應對不同螢幕大小解析度或是螢幕方向的問題,同時也解決了在localization上會遇到的問題包括一些從右讀到左的語言。

      Auto Layout工具基本介紹:下面這些按鈕在Storyboard的右下角

      (圖片取自AppCoda網站)

      Align – 創造「對齊」相關的constraint
      右邊的數字是可以設定你要它離開中心點多遠,如果你要它在正中心的話,當然就設定為零就可以了。

      Pin – 創造spacing(空間)相關的constraint



      Issues – Resolve layout issues.


      Resizing – Specify how resizing affects constraints.
      Sibling 兄弟
      Ancestor 祖先
      Descendants 後人
      (這三個選項還不知道是做什麼的,只是先把英文翻出來Orz)

      有時創造的constraint會互相衝突,這些衝突顯示在Interface Builder outline view上,點選Storyboard右下角的按鈕就可以展開,就像寫程式一樣,如果警示的圖案中間是個圓圈的話,Xcode還會幫你修正自動加上它認為最合適的constraint。
      (圖片取自AppCoda網站)


      右邊的Utilities裡的Size inspector,顯示每個constraint以及其數據,也可以在這裡直接編輯,再下面可以設定各個contraint的priority。

      網路上找到別人寫的各個工具的細項介紹:IOS7.0 Xcode5 AutoLayout 备忘录


      正常成功的constraint在Storyboard上是顯示藍色的
      (圖片取自AppCoda網站)

       如果現有的constraint不足以完整地義該物件要放在哪裡,constraint就會是黃色的
      (圖片取自AppCoda網站)


             設定Auto Layout就像寫程式一樣,背後也有一套邏輯在運作,只要跟著邏輯走就沒錯了。

             設定Auto Layout的時候要同時考慮該物件的「長寬」以及「位置」,初學者一開始都只有在思考位置的問題,但這樣該物件的的大小形狀就會被擠壓到。
             以下面這張圖為例,可以看到分別有兩條設定長寬constraint跟四條設定置中的constrain,如果只有設定置中的contraint的話,在preview裡面是完全看不到東西的,因為沒有設定該物件的長寬,所以這個色塊會被縮小成一點完全看不見。
      但如果該物件的長寬是intrinsic Size,我們一般不會設定它的長寬,會讓它自動隨著需要做改變,像button跟label都是intrinsic size。

      其實Auto Layout除了用constraint設定外,也可以用程式設定,關於Auto Layout的API是NSLayoutConstraint,不過用Xcode就可以完成大部份的Layout設定了,如果真的要用程式碼來設定那應該是相當複雜,網路上關於這方面教學文更是少之又少,我目前只有找到下面這幾篇是在講程式的:
      NSLayoutConstraint 動態產生 Auto Layout 的效果
      AutoLayout (2) 手動建立 NSLayoutConstraint


      專有名詞解釋:

      Leading Space:左邊
      Trailing Space:右邊
      inferred:推斷
      Standard Value:Xcode建議的間隔大小


      設定Auto Layout 的小訣竅:

      1. 在設定constraint時最好不要設定特定的數字,不管是位置還是長寬。除非你自己很清楚我就是要讓某個關係(長寬或間格)是在特定的數字。
      2. 在設定Auto Layout時要同時思考position跟size的問題

      Xcode 6新增的功能:
      Compact Width | Compact Height : iPhone in landscape
      Compact Width | Regular Height : iPhone in portrait
      Regular Width | Regular Height : iPad in portrait or landscape
      所有設定一開始都一定要設定在Any Width | Any Height,要不然該設定就只會設定在特定的螢幕大小裡


      相關WWDC Session:

      • 2011 Session 103 : Cocoa Autolayout
        • Basics
        • Runtime
        • Layering
        • Debugging
        • Transition
        • 2012 Session 202 : Introduction to Auto Layout for iOS and OS X
          • Setting up Constraint-Based Layout
          • Layout Behind the Scenes
          • The Visual Format Language:make your code more easier to read
          • Things That Can Go Wrong
          • Compatibility Issue
        • 2012 Session 228 : Best Practices for mastering Auto Layout
          • 教程式
        • 2012 Session 232 : Auto Layout By Example
          • Transitioning to Auto Layout
          • Explicit Widths
          • Localization
          • New API
          • Animation
          • 2013 Session 406 : Taking Control of Auto Layout in Xcode 5
            • 一開始還是有介紹一下Auto Layout,主要都是示範,相當值得一看,到後面有比較複雜的操作。
          史丹佛的課程:9. Animation and Autolayout(從25分開始講Auto Layout)

          這個課程設計的非常棒,在短短四十分鐘裡就講了很多東西,強烈建議一定要看,其中他介紹了設定Auto Layout的三種方式:
          1. 使用Xcode建議的constraint:方法是把物件放在Xcode推薦的blue guidelines上,然後再按下Issues的Reset to Suggested Constraints選項,Xcode就會自動幫你設定他認為最適合的constraint,而要Xcode設定到最正確的constraint就是要用Xcode建議的blue guidelines。
          2. 使用下面Align跟Pin的功能
          3. 使用control-drag的方式創造constraint:如果在物件內部拖曳,可以設定長寬,橫著拖曳可以設定寬度,直著拖曳可以設定高度,斜著拖曳可以設定長寬比;如果點住該物件往外面空的地方拖曳,可以設定與邊界的間隔;如果往其他物件身上拖曳,可以設定兩個物件的關係。


          教學文:

          Introduction to Auto Layout(AppCoda):非常非常非常簡略的介紹,光看這篇的話是絕對學不會的,不過可以當作最入門的文章,因為Auto Layourt東西實在很多,一開始就看長篇大論教學文實在會很令人心煩。

          Beginning Auto Layout in iOS 6(Ray Wenderlich):非常長很詳細,有分Part1, Part2。從上一代作layout的技術autosizing masks的缺點講起,我想如果是iOS的初學者,這部分就可以跳過了,直接從Designing like you mean it這個部分開始看就可以了,我們不需要知道以前的技術有多麼的不方便,如果是從iOS 6前就開始開發iOS的人才比較需要看這段,比較兩個技術的差別也比較容易轉換到Auto Layout。
          • Auto Layout的運作邏輯 Designing Like You Mean It:
            • The big advantage of using constraints is that you no longer have to fiddle with coordinates to get your views to appear in the proper places. Instead, you can describe to Auto Layout how the views are related to each other and Auto Layout will do all the hard work for you. This is called designing by intent.
            • When you design by intent, you’re expressing what you want to accomplish but not necessarily how it should be accomplished. Instead of saying: “the button’s top-left corner is at coordinates (20, 230)”, you now say: “The button is centered vertically in its superview, and it is placed at a fixed distance from the left edge of the superview.”
            • Using this description, Auto Layout can automatically calculate where your button should appear, no matter how big or small that superview is.
            • This makes the design of your user interfaces much more descriptive. You simply define the constraints, and the system calculates the frames for you automatically.
          • Interface Builder only adds new constraints when the existing ones are no longer adequate.
          • 名詞解釋:User constraint,比較粗的那種T-bar。
          Auto-Layout-Showcase:Project for demonstrating several auto layout techniques on iOS.
          《Auto Layout 使用心得》系列文章

          相關工具:

          可以幫你寫 constraint 的 code
          http://constraints.icodeforlove.com/

          Code
          FLKAutoLayout:FLKAutoLayout is a category on UIView which makes it easy to setup layout constraints in code.


          相關討論

          https://www.facebook.com/groups/iostw/permalink/990792090948140/
          解法:

          Superview.bottom = label.top x 3 + 150
          在storyboard中 multiplier設定3 constant設定150

          根據要求,上下空間比例為 1:2,所以上下加起來的空間高度是上面空間高度的三倍,然後還差 img 的高度 150

          於是上面空間 x 3 + 150 就等於整個畫面的高度

          上面空間是 label.top
          整個畫面的高度則是 Superview.bottom


          深入探討:

          影片
          1. Achieving Zen With Auto Layout(投影片)


          2. Auto Layout v.s Programmatically Layout by Claire Chang + Jamie Sa + Zonble @Cocoaheads Taipei


          文章
          1. iOS Autolayout Fun Facts and Tips
          2. 10 Things You Need To Know About Cocoa Auto Layout
          3. Content Compression and Hugging in Auto Layout


          蘋果官方文件:Auto Layout Guide


          Auto Layout的東西真的非常多,如果要打算一開始就把所有的東西都看完,我想是不太可能的,因為像priority這樣非常深入的工具,如果自己沒有這個需要,那是很難體會它的實用性,就算硬去學跟著操作一遍我想也是根本記不起來的。

          我個人推薦學習Auto Layout的順序是:
          1. 先看些非常簡單的教學,像是AppCoda這篇
          2. 然後再去一部教學影片,比如說史丹佛上課的那部
          3. 然後再去了解全部Auto Layout的功能,了解知道就好,這樣之後遇到問題就知道要往哪裡深入了解,可以看我這篇文章一開始的介紹,我把所有關於Auto Layout的工具都介紹過一遍了(如有遺漏請告訴我,感謝~)