I os 09
- 2. 內容⼤大綱
• Storyboard 初探
• QV091:Storyboard 及轉場效果
• QV109:Static Table (懶⼈人表格)
• 多畫⾯面之切換及轉場動畫
• QV035:兩個畫⾯面的切換
• QV036:幾種不同的畫⾯面切換⽅方式
• 網⾴頁⾴頁⾯面切換
• QV042:UIWebView ⽤用法
(結合 UISegmentedcontrol 讀取外部網⾴頁)
• Samples:TBHintView (3rd Party ActionSheet)
- 16. 設注意分別選擇:
均有不同的屬性
(1) Table View
內容可以設定
(2) Table View Cell
(3) Label
- 21. UIView 切換動畫相關之⽅方法
+ (void) beginAnimation
+ (void) setAnimationDuration
+ (void) setAnimationCurve
+ (void) setAnimationTransition
+ (void) commitAnimations
- 24. 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];
}
- 25. 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];
}
- 27. - (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];
}
- 31. ⽅方法三:presentViewController
[A presentViewController:B
animated: completion:]
[B dismissViewControllerAnimated:
completion:]
包含切換完成後的處理程序
- 37. 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;
}
- 38. 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]]];
}
}
- 40. 範例:
TBHintView
3rd Party : ActionSheet