Created
December 8, 2010 04:12
-
-
Save marshluca/732869 to your computer and use it in GitHub Desktop.
移动到新的位置
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface DragView : UIImageView | |
{ | |
CGPoint startLocation; | |
} | |
@end | |
@implementation DragView | |
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event | |
{ | |
// Retrieve the touch point | |
CGPoint pt = [[touches anyObject] locationInView:self]; | |
startLocation = pt; | |
[[self superview] bringSubviewToFront:self]; | |
} | |
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event | |
{ | |
// Move relative to the original touch point | |
CGPoint pt = [[touches anyObject] locationInView:self]; | |
CGRect frame = [self frame]; | |
frame.origin.x += pt.x - startLocation.x; | |
frame.origin.y += pt.y - startLocation.y; | |
[self setFrame:frame]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
写的不错哦 我也是刚学这个 不太明白 bringSubviewToFront的意思