0

目標:画像をドラッグするとフェードになり、背景ビューが表示されるようにしたい。

ドラッグ時に画像のアルファ値を増減するにはどうすればよいですか?

ありがとう

4

2 に答える 2

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 に答える
2

image.alphaを減らしますtouchesBegan。で増やしtouchesEndます。

于 2012-07-02T10:43:03.963 に答える