用两个imageView做框架实现数据仪表:
if(kViewWidth==kViewHeight) {
self.backImageView= [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,kViewWidth,kViewWidth/2.0)];
}elseif(kViewHeight>kViewWidth){
self.backImageView= [[UIImageViewalloc]initWithFrame:CGRectMake(0,(kViewHeight-kViewWidth) /2.0,kViewWidth,kViewWidth/2.0)];
}else{
self.backImageView= [[UIImageViewalloc]initWithFrame:CGRectMake((kViewWidth-kViewHeight)/2.0,0,kViewHeight,kViewHeight/2.0)];
}
self.backImageView.contentMode=UIViewContentModeScaleAspectFill;
[selfaddSubview:self.backImageView];
self.pointerImageView= [[UIImageViewalloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.backImageView.frame),CGRectGetWidth(self.backImageView.frame) /2.0,5)];
[self.backImageViewaddSubview:self.pointerImageView];
实现锚点以及动画:
CGRectoldFrame =self.dashView.pointerImageView.frame;
oldFrame.origin.y= oldFrame.origin.y-5;
self.dashView.pointerImageView.layer.anchorPoint=CGPointMake(1,1); // 锚点
self.dashView.pointerImageView.frame= oldFrame; // 恢复原有的frame
[UIViewanimateWithDuration:3animations:^{
CGAffineTransformtransform =CGAffineTransformMakeRotation(120*M_PI/180.0);
[self.dashView.pointerImageViewsetTransform:transform];
}];