SlideShare a Scribd company logo
Class 09
iOS 應⽤用軟體設計
內容⼤大綱
•   Storyboard 初探
    •   QV091:Storyboard 及轉場效果
    •   QV109:Static Table (懶⼈人表格)
•   多畫⾯面之切換及轉場動畫
    •   QV035:兩個畫⾯面的切換
    •   QV036:幾種不同的畫⾯面切換⽅方式
•   網⾴頁⾴頁⾯面切換
    •   QV042:UIWebView ⽤用法
        (結合 UISegmentedcontrol 讀取外部網⾴頁)
    •   Samples:TBHintView (3rd Party ActionSheet)
Storyboard 初探
Project QV091


Storyboard
轉場效果
使⽤用 Storyboards




產⽣生檔案
MainStoryboard.storyboard




                    拖移產⽣生新的
                    View Controller
各別 UIViewController
 及內部物件的設計
(1) 按住 Ctrol,滑⿏鼠按下後從
  按鈕拖移到右邊 UIView




                 (2) 選擇 Modal
選擇 Modal Segue
(接⼊入下個樂章,轉場)      設定轉場效果
同理,製作返回功能
四種轉場效果

Cover Vertical (垂直翻⾴頁)
Flip Horizonal (⽔水平翻轉)
Cross Dissolve (⼗十字溶解)
Partial Curl (部份捲曲)
Static table
(懶⼈人表格)
Project QV109


Storyboard
Static Table
拖移 Table View Controller 進來
設定屬性:Static Cells、
選擇 TableView    區段數⺫⽬目、群組⾵風格
設注意分別選擇:
                      均有不同的屬性
(1) Table View
                      內容可以設定
(2) Table View Cell
(3) Label
I os 09
表格內各格⼦子點選後顯⽰示的畫⾯面,亦可採⽤用設定完成
多畫⾯面之切換及轉場動畫
Project QV035


兩個畫⾯面間的切換
⾴頁⾯面切換之Animation動畫
UIView 切換動畫相關之⽅方法

+ (void) beginAnimation
+ (void) setAnimationDuration
+ (void) setAnimationCurve
+ (void) setAnimationTransition
+ (void) commitAnimations
動畫切換之過渡效果

UIViewAnimationTransitionFlipFromLeft (從左側翻轉)
UIViewAnimationTransitionFlipFromRight (從右側翻轉)
UIViewAnimationTransitionCurlUp (往上捲起)
UIViewAnimationTransitionCurlDown (往下捲起)
UIViewAnimationTransitionNone (無效果)
ViewController.h



#import <UIKit/UIKit.h>
@class SwitchView;

@interface ViewController : UIViewController
{
    SwitchView *switchView;
}

@end
ViewController.m (1/2)
#import "ViewController.h"
#import "SwitchView.h"

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(120, 250, 80, 40);
    [myButton setTitle:@"Switch" forState:UIControlStateNormal];
    [myButton addTarget:self
                 action:@selector(onSwitch:)
       forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview: myButton];

    self.view.backgroundColor = [UIColor redColor];
}
ViewController.m (2/2)


- (void)onSwitch:(id)sender
{
! switchView = [[SwitchView alloc]
                 initWithNibName:@"SwitchView" bundle:nil];

! [self.view addSubview:switchView.view];

!   // 加⼊入動畫
!   [UIView beginAnimations:@"flipview" context:nil];
!   [UIView setAnimationDuration:0.5];
!   [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
!   [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
!   !   ! ! ! !        forView:self.view cache:YES];

! [UIView commitAnimations];
}
SwitchView.h




#import <UIKit/UIKit.h>

@interface SwitchView : UIViewController

-(void) onBack:(id)sender;

@end
- (void)viewDidLoad
{                                                      SwitchView.m
    [super viewDidLoad];

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(120, 350, 80, 40);
    [myButton setTitle:@"Back" forState:UIControlStateNormal];
    [myButton addTarget:self
                 action:@selector(onBack:)
       forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview: myButton];
    self.view.backgroundColor = [UIColor blueColor];
}


- (void)onBack:(id)sender
{
! [UIView beginAnimations:@"flipview" context:nil];
! [UIView setAnimationDuration:5];
! [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
! [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
! !   ! ! ! !        forView:self.view.superview cache:YES];

    [self.view removeFromSuperview];

    [UIView commitAnimations];
}
Project QV036
簡單的兩個⾴頁⾯面切換,但改
⽤用xib處理畫⾯面
三種常⽤用⽅方法
addSubView
presentModalViewController
presentViewController
畫⾯面間的切換
⽅方法⼀一:視為⼦子畫⾯面新增加⼊入



        [A.view addSubview:B.view]




       [B.view removeFromSuperview]
⽅方法⼆二:presentModalViewController
           注意:已在 iOS5 中移除




      [A presentModalViewController:B animated:]




       [B dismissModalViewControllerAnimated:]
⽅方法三:presentViewController

           [A presentViewController:B
             animated: completion:]




        [B dismissViewControllerAnimated:
                  completion:]




                                 包含切換完成後的處理程序
討論問題


presentView 適⽤用時機?
presentView 和 ActionSheet 之異同?
網⾴頁切換 UIWebView

• QV042:UIWebView ⽤用法
 (結合 UISegmentedcontrol 讀取外部網⾴頁)
Project QV042

點選項⺫⽬目按鈕,進⼊入網站
UISegmentedControl
UIWebView
連結外部網站與內部網⾴頁檔
ViewController.h



#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UISegmentedControl *segmentedControl;
    IBOutlet UIWebView *webView;

    NSArray *nameArray;
    NSArray *linkArray;
}

- (IBAction) change:(id)sender;

@end
ViewController.xib
ViewController.m (1/2)
  - (void)viewDidLoad
  {
      [super viewDidLoad];

      //建⽴立陣列並設定其內容來當作選項
      nameArray =[NSArray arrayWithObjects:
                           @"三寶家庭",
                           @"Yahoo!",
                           @"Google",
                           @"Apple",
                           nil];
                                                   在迴圈內逐⼀一指定
   linkArray =[NSArray arrayWithObjects:
                        @"page1",
                        @"http://www.yahoo.com.tw/",
內部檔案之主檔名                @"http://www.google.com/",
                        @"http://www.apple.com/",
                        nil];

      //使⽤用陣列來建⽴立UISegmentedControl
      for(int i=0; i<segmentedControl.numberOfSegments; i++)
      {
          NSString *str = [nameArray objectAtIndex:i];
          [segmentedControl setTitle:str forSegmentAtIndex:i];
      }
      // segmentedControl.selectedSegmentIndex = 2;
  }
ViewController.m (2/2)
- (IBAction)change:(id)sender
{
    NSString *link = [linkArray objectAtIndex:[sender
selectedSegmentIndex]];
    NSString *str1 = [link substringToIndex:4];
    NSString *str2 = [NSString stringWithFormat:@"http"];

    if([str1 isEqualToString:str2])
    {
        // 讀網⾴頁
         [webView loadRequest:[NSURLRequest
                          requestWithURL:[NSURL URLWithString:link]]];
    }
    else
    {
        // 讀檔案
         [webView loadRequest:[NSURLRequest requestWithURL:[NSURL
                         fileURLWithPath:[[NSBundle mainBundle]
                         pathForResource:link
                                  ofType:@"htm"]isDirectory:NO]]];

    }
}
問題

是否可以使⽤用陣列來定義按鈕的項⺫⽬目?
參考:關於 UISegmentedControl 的基
本設定⽅方式
(http://furnacedigital.blogspot.com/2011/08/uisegmentedcontrol.html)




網⾴頁切換有其它的⽅方法嗎?
範例:
      TBHintView
 3rd Party : ActionSheet
http://furnacedigital.blogspot.com/2012/05/tbhintview-uiactionsheet.html
I os 09
............

More Related Content

PPTX
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
DOC
用Jquery实现拖拽层
PDF
I os 07
PDF
11 UINavigationController
PDF
I os 14
PPTX
前端MVC之backbone
PDF
10 Editing UITableView
PDF
Kissy design
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
用Jquery实现拖拽层
I os 07
11 UINavigationController
I os 14
前端MVC之backbone
10 Editing UITableView
Kissy design

What's hot (15)

PDF
06 Subclassing UIView and UIScrollView
PPTX
Script with engine
PDF
09 UITableView and UITableViewController
PDF
Kissy简介
PDF
I os 01
PPTX
Asp.net開發要注意的是?
PDF
從改寫後台 jQuery 開始的 Vue.js 宣告式渲染
PDF
15 Subclassing UITableViewCell
PDF
I os 10
PDF
07 View Controllers
PDF
程式人雜誌 2015年三月
PPTX
jQuery 選取器解析
PPTX
YUI介绍和使用YUI构建web应用
PDF
程式人雜誌 -- 2015 年1月號
PDF
08 Notification and Rotation
06 Subclassing UIView and UIScrollView
Script with engine
09 UITableView and UITableViewController
Kissy简介
I os 01
Asp.net開發要注意的是?
從改寫後台 jQuery 開始的 Vue.js 宣告式渲染
15 Subclassing UITableViewCell
I os 10
07 View Controllers
程式人雜誌 2015年三月
jQuery 選取器解析
YUI介绍和使用YUI构建web应用
程式人雜誌 -- 2015 年1月號
08 Notification and Rotation
Ad

Viewers also liked (11)

PDF
I os 04
PDF
課程規畫
PDF
I os 16
PDF
I os 05
PDF
I os 02
PDF
I os 11
PDF
I os 03
PDF
I os 15
PDF
I os 08
PDF
I os 06
PDF
I os 13
I os 04
課程規畫
I os 16
I os 05
I os 02
I os 11
I os 03
I os 15
I os 08
I os 06
I os 13
Ad

Similar to I os 09 (20)

PPT
YUIconf2010介绍
PDF
Spring 2.x 中文
PDF
Android 智慧型手機程式設計
PDF
ASP.NET Core MVC 2.2從開發到測試 - Development & Unit Testing
PDF
掌星 移动互联网开发笔记-Vol001
PDF
用 Standalone Component 來寫 Angular 吧! - STUDY4.TW 2023 小聚 - 聊前端
PPT
JdonFramework中文
PDF
Core data lightweight_migration
PDF
13 UIPopoverController and Modal View Controller
PDF
透過 Windows Azure Mobile Services 開發各平台 Apps
PDF
20250422 從零開始的 Angular 網頁應用程式 Part II: Service & Routing & Form
PDF
105-2 iOS程式設計(六)
PDF
Uliweb cheat sheet_0.1
PDF
怎樣在 Flutter app 中使用 Google Maps
PDF
Backbone.js and MVW 101
PDF
Unity遊戲程式設計 - 應用Sprite物件
PPTX
2016輕鬆開發自有網路地圖工作坊 進階班 0701
ODP
Backbone js and requirejs
PDF
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
YUIconf2010介绍
Spring 2.x 中文
Android 智慧型手機程式設計
ASP.NET Core MVC 2.2從開發到測試 - Development & Unit Testing
掌星 移动互联网开发笔记-Vol001
用 Standalone Component 來寫 Angular 吧! - STUDY4.TW 2023 小聚 - 聊前端
JdonFramework中文
Core data lightweight_migration
13 UIPopoverController and Modal View Controller
透過 Windows Azure Mobile Services 開發各平台 Apps
20250422 從零開始的 Angular 網頁應用程式 Part II: Service & Routing & Form
105-2 iOS程式設計(六)
Uliweb cheat sheet_0.1
怎樣在 Flutter app 中使用 Google Maps
Backbone.js and MVW 101
Unity遊戲程式設計 - 應用Sprite物件
2016輕鬆開發自有網路地圖工作坊 進階班 0701
Backbone js and requirejs
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式

More from 信嘉 陳 (12)

PDF
Processing 06
PDF
Processing 05
PDF
Processing 04
PDF
Processing 03
PDF
Processing 02
PDF
Processing 01
PDF
Processing 09
PDF
Processing 08
PDF
Processing 07
PPT
Google 街景
PPT
社群網站 Facebook
PPT
網路搜尋
Processing 06
Processing 05
Processing 04
Processing 03
Processing 02
Processing 01
Processing 09
Processing 08
Processing 07
Google 街景
社群網站 Facebook
網路搜尋

I os 09