目标:我希望当我拖动图像时它会变淡,这样我们就可以看到背景视图。
我们如何在拖动时间增加或减少图像的 alpha 值?
谢谢
减少你image.alpha
的touchesBegan
. 增加它在touchesEnd
.
我认为您要求提供示例代码。您可以创建 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];
}