主要的实现要点:
1> 自定义按钮的imageRectForContentRect
- (CGRect)imageRectForContentRect:(CGRect)contentRect{
CGFloat imageWidth = 40;
CGFloat imageHeight = 47;
CGFloat x = (contentRect.size.width- imageWidth)*0.5;
// CGFloat y = (contentRect.size.height-imageHeight)*0.5;
CGFloat y =20;
return CGRectMake(x, y, imageWidth, imageHeight);
}
/**
determines whether the receiver is highlighted.
*/
- (void)setHighlighted:(BOOL)highlighted{//不做任何事情的时候,可以去掉按钮的高亮状态的一些效果
}
2>添加转盘按钮
//1. 设置选中按钮时的背景图片--选中状态需要自己管理
[btn setBackgroundImage:[UIImage imageNamed:@"LuckyRototeSelected"] forState:UIControlStateSelected];
//2.设置正常状态的背景图片
[btn setImage:[self clipImageWithName:imageForNormalName index:i count:KButtonCount] forState:UIControlStateNormal];
//设置选中的背景图片
3> 图片的裁剪(从大图中裁剪有规律的小图)
#pragma mark - 按钮的图片裁剪
/**
裁剪的图片名称 name
裁剪第几个小图片 index
大图片的小图片个数 count
*/
- (UIImage*) clipImageWithName:(NSString*)name index:(int)i count:(float)count{
//裁剪的大图片
UIImage *bigImage = [UIImage imageNamed:name];
//设置裁剪的尺寸
CGFloat scale =[UIScreen mainScreen].scale;
//将点转换为像素点
/*
For standard-resolution displays, the scale factor is 1.0 and one point equals one pixel. For Retina displays, the scale factor is 2.0 and one point is represented by four pixels.
*/
CGFloat smallImageWidth = bigImage.size.width/count*scale;
CGFloat smallImageHeight = bigImage.size.height*scale;
CGFloat smallImageX = i*smallImageWidth;
CGRect clipRect = CGRectMake(smallImageX, 0, smallImageWidth, smallImageHeight);
CGImageRef smallImageRef = CGImageCreateWithImageInRect(bigImage.CGImage, clipRect);
return [UIImage imageWithCGImage:smallImageRef];
}
4>快速旋转: 孤度的计算
#pragma mark - 快速旋转
- (IBAction)chooseNO:(UIButton *)sender {
//3、快点旋转
/** 核心动画的缺点是改变不了真是的属性*/
CABasicAnimation *animation = [CABasicAnimation animation];
//设置动画对象属性
[animation setKeyPath:@"transform.rotation"];
[animation setToValue:@(M_PI*3)];
[animation setDuration:0.5];
[animation setDelegate:self];
[self.roattionImageView.layer addAnimation:animation forKey:nil];
}
作者:u011018979 发表于2017/7/2 17:36:15 原文链接
阅读:25 评论:0 查看评论