标签:
创建星星视图:
//星星
_myview = [[UIView alloc]initWithFrame:CGRectMake(95, 5, 200, 50)];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(huadong:)];
[_myview addGestureRecognizer:pan];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dianji:)];
[_myview addGestureRecognizer:tap];
[view1 addSubview:_myview];
for (int i = 0; i < 5; i++) {
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"star01"]];
imageView.frame = CGRectMake(_myview.bounds.origin.x+((i+1)*24), _myview.bounds.origin.y, 24, 24);
[_myview addSubview:imageView];
[_allStar addObject:imageView];
}
//分别在点击和滑动手势实现方法
#pragma mark - 滑动的坐标
-(void)huadong:(UIPanGestureRecognizer *)pan{
CGPoint translation = [pan locationInView:_myview];
for(int i = 0;i < 5 ; i++)
{
UIImageView *im ;
im = _allStar[i];
//NSLog(@"_all[%i] = (%f,%f)",i,im.frame.origin.x,im.frame.origin.y);
if ((translation.x > 0)&&(translation.x < 144)&&(translation.y > 0)&&(translation.y < 24))
{
NSString *myscore = [NSString stringWithFormat:@"%i",((int)translation.x)/24];
//UILabel *score = [[UILabel alloc]initWithFrame:CGRectMake(150, 180, 100, 100)];
//[scrollView addSubview:score];
//score.text = myscore;//_score是一个UILable,myscore为分数,显示在给用户看,关于这个不在赘述
star = [myscore intValue];
//星星
if (im.frame.origin.x > translation.x)
{
im.image =[UIImage imageNamed:@"star01"];
}
else
{
im.image =[UIImage imageNamed:@"star02"];
}
}
}
}
#pragma mark - 点击的坐标
-(void)dianji:(UITapGestureRecognizer *)tap{
CGPoint translation = [tap locationInView:_myview];
for(int i = 0;i < 5 ; i++){
UIImageView *im ;
im = _allStar[i];
if ((translation.x > 0)&&(translation.x < 144)&&(translation.y > 0)&&(translation.y < 24)) {
NSString *myscore = [NSString stringWithFormat:@"%i",((int)translation.x)/24];
//星星
star = [myscore intValue];
if (im.frame.origin.x > translation.x) {
im.image =[UIImage imageNamed:@"star01"];
}else{
im.image =[UIImage imageNamed:@"star02"];
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/damnbird/p/4911061.html