設置NSTimer限制ImageView圖片顯示時間

 //創建一個UIimageView
    
    UIImage *image1 = [UIImage imageNamed:@"weixin.png"];
    
   self.imageView1 = [[UIImageView alloc] initWithImage:image1];
    [self.window addSubview:self.imageView1];
   //設置一個倒計時間
  self.secondsCountDown = 3.0;//3秒倒計時
    //創建一個NSTimer計時器
   self.countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];




//countDownTimer計時器方法
-(void)timeFireMethod{
   self.secondsCountDown--;
    if(self.secondsCountDown == 0){
        //如果計時結束countDownTimer被無效
        [self.countDownTimer invalidate];
        //imageView1透明度設置爲0
        self.imageView1.alpha = 0.0;
    }

}






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章