Re: [問題] fadein和fadeout的連續動作

看板MacDev作者 (完成這條天堂路)時間13年前 (2011/12/26 14:44), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串2/2 (看更多)
我是不太明白你為何要寫在viewDidLoad 手機上要看得到 view是等到viewDidAppear 而且viewDidLoad 只有物件被初始化執行後會被call 基本上只會執行一次 切換view時或在不同viewController 之間切換 都不會再被call 另外還有一個很怪的問題 你fadeIn完成時間是5.5+3.0 那fadeOute 至少也要等fadeIn做完吧 = = 所以我把duration 改成2秒 方法一 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [NSTimer scheduledTimerWithTimeInterval:5.5 target:self selector:@selector(fadeIn) userInfo:nil repeats:NO]; [NSTimer scheduledTimerWithTimeInterval:7.5 target:self selector:@selector(fadeOut) userInfo:nil repeats:NO]; } 方法二 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow:5.5f]]; [self fadeIn]; [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow:2.0f]]; // 5.5+2.0 = 7.5 [self fadeOut]; } ------------------------------------------- -(void)fadeIn{ [UIImageView beginAnimations:nil context:nil]; [UIImageView setAnimationDuration:2.0f]; [father setAlpha:1.0f]; [UIImageView commitAnimations]; } -(void)fadeOut{ [UIImageView beginAnimations:nil context:nil]; [UIImageView setAnimationDuration:2.0f]; [father setAlpha:0.0f]; [UIImageView commitAnimations]; } ※ 引述《sdanielle (DREAM)》之銘言: : 謝謝上次板友提供我寶貴的意見幫了我很大的忙 : 目前出現一個問題就是 : 我想讓father這個物件在5點5秒時fadein : 然後在7點5秒時fadeout : 下面是我的程式碼,結果他只能出現最後那個fadeout : 自己試很多方法結果還是找不出為什麼 : 不曉得是哪裡有錯, : 懇請各位高手幫忙解決~~謝謝 : ViewController.h : - (void)viewDidLoad : { : [super viewDidLoad]; : [NSTimer scheduledTimerWithTimeInterval:0.0 target:self : selector:@selector(fadein2:) : userInfo:nil repeats:NO]; : [NSTimer scheduledTimerWithTimeInterval:0.0 target:self : selector:@selector(fadeout1:) : userInfo:nil repeats:NO]; : } : -(void)fadein1:(NSTimer*)timer : { : [UIImageView beginAnimations:NULL context:nil]; : [UIImageView setAnimationDuration:3]; : [UIImageView setAnimationDelay:5.5] ; : [father setAlpha:1]; : [UIImageView commitAnimations]; : } : -(void)fadeout1:(NSTimer*)timer : { : [UIImageView beginAnimations:NULL context:nil]; : [UIImageView setAnimationDuration:3]; : [UIImageView setAnimationDelay:7.5] ; : [father setAlpha:0]; : [UIImageView commitAnimations]; : } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 42.72.26.9 ※ 編輯: reon 來自: 42.72.26.9 (12/26 14:57) ※ 編輯: reon 來自: 42.72.26.9 (12/26 15:01)

12/26 17:51, , 1F
對哦@@!因為我是看網路上的教學然後拼拼湊湊寫出來的
12/26 17:51, 1F

12/26 17:52, , 2F
r大的式子簡潔易懂,我已經了解怎麼運用了~非常感謝~~
12/26 17:52, 2F
文章代碼(AID): #1E-1VN7h (MacDev)
文章代碼(AID): #1E-1VN7h (MacDev)