0

目标:我希望当我拖动图像时它会变淡,这样我们就可以看到背景视图。

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

谢谢

4

2 回答 2

2

减少你image.alphatouchesBegan. 增加它在touchesEnd.

于 2012-07-02T10:43:03.963 回答
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];
 }
于 2012-07-02T10:47:10.667 回答