2012-07-02 42 views

回答

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]; 
} 
2

減少你image.alphatouchesBegan。在touchesEnd增加它。