Just My Life & My Work

Posts tagged ‘teach’

[Xamarin][iOS] 多螢幕:電話字 (Sample Project: Phoneword)

承接深度了解專案:電話字 (Sample Project: Phoneword),再來學習多螢幕架構,同樣也是跟Xcode非常相似的做法,看到介面很快就能上手!

Xamarin phoneword00010

簡直就一模一樣嘛⋯⋯view controller的連結也是透過拉藍色線

過去我鮮少使用Storyboard,多使用Xib,不過因Apple一直在推廣Storyboard(範例程式都以它為主),我們豈能守舊而唯Xib獨尊?想想過去技術高手只想用code,來處理App所有層面的事情,現在看起來是多麽不切實際呢!之所以會發明新的工具,就是想增進開發效率,所以讓我們來擁抱改變吧!

(繼續閱讀…)

[Xamarin][iOS] 深度了解專案:電話字 (Sample Project: Phoneword)

承接範例專案:電話字 (Sample Project: Phoneword),再來就是解釋它怎麼運作,包含Xamarin介面C#程式碼,還有很重要的是Xamarin.iOS Application的剖析。

Xamarin iOS Application03

  • References – Contains the assemblies required to build and run the application. If we expand the directory, we’ll see references to .NET assemblies such as System , System.Core, and System.Xml , as well as a reference to Xamarin’s Xamarin.iOS assembly.
  • Components – The Components directory houses ready-made features from the Xamarin Components store , a public marketplace for Xamarin code. This is similar to the NuGet Gallery for those familiar with Visual Studio. For more information on Xamarin Components, refer to the Xamarin Components walkthrough .
  • Resources – The Resources folder stores icons, launch images, and other media. Xamarin has a separate guide for Working with Resources that explores the role of this directory further.
  • Main.cs – This contains the main entry point of the application. To start the application, we pass in the name of the main application class, the AppDelegate .
  • AppDelegate.cs – This file contains the main application class and is responsible for creating the Window, building the user interface, and listening to events from the operating system.
  • MainStoryboard.storyboard – The Storyboard contains the visual design of the application’s user interface. Storyboard files open in a graphical editor called the iOS Designer.
  • Phoneword_iOSViewController.cs – The View Controller powers the screen (View) that a user sees and touches. The View Controller is responsible for handling interactions between the user and the View.
  • Phoneword_iOSViewController.designer.cs – The designer.cs is an auto-generated file that serves as the glue between controls in the View and their code representations in the View Controller. Because this is an internal plumbing file, the IDE will overwrite any manual changes and most of the time we can ignore this file. For more information on the relationship between the visual Designer and the backing code, refer to the Introduction to the iOS Designer guide.
  • Info.plist – Info.plist is where we set application properties such as the application name, icons, launch images, and more. This is a powerful file and a thorough introduction to it is available in theWorking with Property Lists guide.
  • Entitlements.plist – The entitlements property list lets us specify application capabilities (also called App Store Technologies) such as iCloud, PassKit, and more. More information on theEntitlements.plist can be found in the Working with Property Lists guide. For a general introduction to entitlements, refer to the Device Provisioning guide.

看起來和Xcode裡的檔案架構很類似呢!學習來格外輕鬆~

(繼續閱讀…)

[Xamarin][iOS] 範例專案:工作清單 (Sample Project: Tasky)

在瞭解Xamarin介紹與研究後,接著就去下載並且安裝Xamarin Studio,再來當然就是要來跑「飯粒」專案囉~如此可快速上手Xamarin!

官方提供的範例專案:工作清單 (Sample Project: Tasky),下載後開啟專案,即可直接編譯執行,除了在模擬器 (Simulator)上跑,也能在實機 (Device)上跑呢!而模擬器居然是開啟Xcode附帶的iOS模擬器,所以感覺相當親切:)~

Xamarin before

(繼續閱讀…)

[Xamarin][iOS] 範例專案:電話字 (Sample Project: Phoneword)

有目標的學習是最快學會一套工具的最好方式!於是乎,Xamarin官方的快速開始教學範例專案:電話字 (Sample Project: Phoneword),引領我熟悉這有著神秘面紗的IDE (整合開發環境)

Xamarin Phoneword

這畫面看起來是不是很像Xcode的樣子呀?!

(繼續閱讀…)

[iOS] 延長顯示啟動畫面的時間

Launch Image (Launch Screen)顯示時間是由系統決定,不過我們可透過讓App睡覺的方式,來延長顯示啟動畫面的時間

iPhone_6_Garbage_launch

垃圾管家App開啟畫面為例。

只要一行程式碼,即可做到延遲的效果喔!在AppDelegate.m中:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    sleep(5);
}

參考:increase launch image time on xcode

圖片

[iOS] iPhone 螢幕解析度

今年度開發iOS 8 app,iPhone螢幕解析度需要考慮四種!若考慮所有顯示狀況,同一張圖同時要準備好三種維度的圖:@1x、@2x、@3x,其實只要看這張圖就知道我想表達什麼了!

iphone-screen-size-ppi

今日和夥伴做Side Project,體會到@3x圖的重要性!在iPhone 6以下都能用兩年前開發的色盤選色技術,然而在iPhone 6+卻會有問題,原因是少準備@3x圖:P~

參考:你的興趣真的可以改變世界!Instagram、Uber 的創辦人就做到了別再苦苦經營粉絲團!Side project 在三個月內救了我的新創公司

[iOS] iOS 8 Remote/Local Notification

每年iOS更新後,SDK中多少會有些API在最新的版本被棄用,此時就要去寫condition code分別跑在不同版本的iOS。Notification也在iOS 8有所變動,包含Remote Notification與Local Notification,我們就來看怎麼改比較容易吧~

iOS 8 Remote:Local Notification

如果沒有處理iOS 8的情況,是不會跳出請求允許傳送通知的提示喔!

(繼續閱讀…)

[iOS] 在App間分享資料 (Share Data Between Apps)

過去App的資料是被保護在沙盒(Sandbox)之中,因此無法讓其它App來存取。現在Apple設計一個共享區域,在此區域可以讓不同的App來存取,只是這些App必須是同一個開發者呢!

在App間分享資料 (Share Data Between Apps)

在專案中的Capabilities中打開App Groups,接著創立一個App Groups,我這裡是設定group.happy.share,程式碼中會用到喔~

(繼續閱讀…)

[iOS] WatchKit 與 UIKit

Apple Watch即將上市,對iOS開發者而言,無疑是個一定要了解的全新裝置,特別是在使用者體驗上,如何設計適合小螢幕的界面。這種改變從電腦轉移到手機已經歷過一次,如今要從手機移轉到手錶,螢幕可是越變越小呢~

手機上所呈現的界面是透過UIKit framework,而手錶所呈現的界面則是透過WatchKit framework,這兩者有相似的地方,也有許多不一樣的地方

WatchKit 與 UIKit

基本上,WatchKit是UIKit的簡化版,之後Apple應該會根據需求新增修改些property或method。一般而言,手錶的功用是瀏覽重於互動,所以framework少有互動的設計。

WatchKit的元件

WKInterfaceObject繼承於NSObject。WKInterfaceImage繼承於WKInterfaceObject、WKInterfaceLabel繼承於WKInterfaceObject,其餘依此類推,都是繼承於WKInterfaceObject。

其property與method也很陽春,只有一些基本的設定。

  • WKInterfaceObject

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <WatchKit/WKDefines.h>

WK_CLASS_AVAILABLE_IOS(8_2)
@interface WKInterfaceObject : NSObject

- (instancetype)init NS_UNAVAILABLE;

- (void)setHidden:(BOOL)hidden;
- (void)setAlpha:(CGFloat)alpha;

- (void)setWidth:(CGFloat)width;   // setting to 0 means use natural size. ignored for table
- (void)setHeight:(CGFloat)height;

@property(nonatomic,readonly,copy) NSString *interfaceProperty;   // same as controller's property name

@end

@interface WKInterfaceObject (WKAccessibility)

- (void)setAccessibilityLabel:(NSString *)accessibilityLabel;
- (void)setAccessibilityHint:(NSString *)accessibilityHint;
- (void)setAccessibilityValue:(NSString *)accessibilityValue;

@end
  • WKInterfaceImage

#import <Foundation/Foundation.h>
#import <WatchKit/WKDefines.h>
#import <WatchKit/WKInterfaceObject.h>

@class UIImage;

WK_CLASS_AVAILABLE_IOS(8_2)
@interface WKInterfaceImage : WKInterfaceObject

- (void)setImage:(UIImage *)image;
- (void)setImageData:(NSData *)imageData;
- (void)setImageNamed:(NSString *)imageName;

- (void)startAnimating;	      // play all images repeatedly using duration specified in interface description
- (void)startAnimatingWithImagesInRange:(NSRange)imageRange duration:(NSTimeInterval)duration repeatCount:(NSInteger)repeatCount; // play subset of images for a certain number of times. 0 means repeat until stop
- (void)stopAnimating;

@end

我們很驚訝地發現,居然沒有frame這個特性!也就是我們無法設定其座標(但可設定長與高),也無法使用Auto Layout。實際上,WatchKit界面元件只能在格子中透過邊界相對位置來放置。

還有許多特性需要好好了解,因為本來就不該把手錶當作手機來設計,而簡化自然有其好處!持續去研究吧~

參考:WatchKit – NSHipster。

[iOS] 大小類別 (Size Class)

大小類別 (Size Class)iOS 8新釋出的類別,主要目的是想要解決設備歧異的問題,透過實作Size Class,我們可以減少許多客製設備類別 (iPhone、iPad)與螢幕大小 (iPhone:3.5吋、4吋、4.7吋、5.5吋,iPad:7.9吋、9.7吋)的程式碼!還有之所以推出,是為了因應未來有更多不一樣螢幕大小的產品(如Apple Watch),所以若能採用Size Class便可減輕開發負擔!

Size Class

其分為普通(Regular)緊密 (Compact)兩個種類(class)。開發者便可以無視實際的尺寸,而是對這兩類和它們的組合進行適應。這樣不論在設計時還是程式碼上,我們都可以不再受限於實際的尺寸,而是變成遵循尺寸的視覺感官來進行適應。

(繼續閱讀…)

標籤雲