拖动图像时我们如何改变alpha值

时间:2012-07-02 10:41:31

标签: iphone ios uiimageview

目标:我想拖动图片时它会变淡,所以我们可以看到背景视图。

我们如何在拖动时间内增加或减少图像的alpha值?

感谢

2 个答案:

答案 0 :(得分:2)

减少image.alpha中的touchesBegan。在touchesEnd中增加它。

答案 1 :(得分:2)

我认为你要的是样本代码。你可以创建一个UIImageView的类子类。像:

·H

@interface YourImageController : UIImageView
{
    CGPoint startLocation;
}
@end

的.m

@implementation YourImageController
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {   
    [self setAlpha:x.x];

    // Retrieve the touch point
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [self setAlpha:x.x];
    CGPoint pt = [[touches anyObject] locationInView:self];
    CGFloat dx = pt.x - startLocation.x;
    CGFloat dy = pt.y - startLocation.y;

    CGPoint newCenter = CGPointMake(self.center.x + dx, self.center.y + dy);

    self.center = newCenter;
}
 -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
 {
    [self setAlpha:1.0];
 }