Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created December 8, 2010 04:12
Show Gist options
  • Save marshluca/732869 to your computer and use it in GitHub Desktop.
Save marshluca/732869 to your computer and use it in GitHub Desktop.
移动到新的位置
#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];
}
@SevenJustin
Copy link

写的不错哦 我也是刚学这个 不太明白 bringSubviewToFront的意思

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment