gpt4 book ai didi

iphone - 拖动图像时如何改变alpha值

转载 作者:行者123 更新时间:2023-11-28 19:17:16 24 4
gpt4 key购买 nike

目标:我希望当我拖动图像时它会变淡以便我们可以看到背景 View 。

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

谢谢

最佳答案

我认为您要求的是示例代码。你可以创建一个 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];
}

关于iphone - 拖动图像时如何改变alpha值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11292041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com