目標:画像をドラッグするとフェードになり、背景ビューが表示されるようにしたい。
ドラッグ時に画像のアルファ値を増減するにはどうすればよいですか?
ありがとう
目標:画像をドラッグするとフェードになり、背景ビューが表示されるようにしたい。
ドラッグ時に画像のアルファ値を増減するにはどうすればよいですか?
ありがとう
サンプルコードを求めていると思います。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];
}
image.alpha
を減らしますtouchesBegan
。で増やしtouchesEnd
ます。