最近使用UIProgressView這個控件,設置了frame
UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, progerssY, SCREEN_WIDTH, 1)];
progressView.tintColor = JzZCOLORRGB(95, 155, 248);
progressView.trackTintColor = [UIColor whiteColor];
[self.view addSubview:progressView];
以上代碼發現高度沒變,然后自己測試了,高度一直為2,但是達不到需求,需求高度為1,然后從網上找來代碼,設置
//改變高度
CGAffineTransform transform = CGAffineTransformMakeScale(1.0f,0.5f); //縮放
這個方法的確是改變了progressView得高度為1,但是progressView得y值也改變,y會移動(2-progressViewH)/2,progressViewH為自己要設置的高度,結果又不符合需求
所以想到組合動畫來實現,
//改變高度還讓y值正確達到想要的位置
CGAffineTransform transform = CGAffineTransformMakeScale(1.0f,0.5f);//縮放,y值向下移動0.5
progressView.transform = CGAffineTransformTranslate(transform, 0, -1);//平移,y值向上移動0.5
以上都是以我想要的高度為1來設置的