Привет, я пытался завершить проект iphone из кулинарной книги разработчиков iphone по перетаскиваемым представлениям, и мне было трудно решить, какие сегменты кода попадают в какой файл, который я некоторое время возился с ним, теперь любой орган может дать мне немного Направление вот код
/*
*DragView: Draggable views
/*
@interface DragView :UIImageView
{
cgpiontstartLocation
}
@end
@implementation DragView
// note the touch piont brings the touched view to the front
-(void) touchesbegan: (NSSet*) touches withevent: (UIEvent*) event
{
CGPoint = [[touches anyObject] locationinView: self;
startlocation = pt;
[[self superview] bringSubviewTofront:self;
}
//as the user drags move the flower with the touch
- (void) touchesMoved (NSSet*) touches withEvent:(uiEvent*) event
{
cg*oint pt = [[touches anyObject] locatoininView:self];
CGRect frame = {self];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self setFrame:frame]
}
@end
и
/*
*Hello Controler: The primer view controller
*/
@@interface HelloController : UIViewController
{
UIView *contentview;
}
@end
@implementation HelloContrller
#define MAXFLOWERS 16
CGPiont randomPoint() { return CGPointMake(random() % 256, random() % 396);}
- (void) loadView
{
//create the main view with a balck backgroung
CGRect apprect = [[UIScreen mainScreen] applicationFrame];
contentView = [[UIVIEW alloc] initwithframe:apprect];
contentView.backgroundColor = [ UIColor blackColor];
self.View = contentView;
[contentView release];
// add the flowers to randompoints on the screen
for (int 1 = 0; i < MAXFLOWERS; i++)
CGRect dragRect = CGRectMake (0.0f, 0.0f, 64.0f64.0f);
dragRect.origin = randomPoint();
DragView *Dragger [[DragView alloc] initwithFrame:dragRect];
[dragger setUserInteractionEnable:YES];
//select random flower
NSString *whichFlower [[NSArray arrayWithObjects:@"bluedove.png",
@"purpledove.png", @"reddove.png",nil] objectAtIndex:(random() %
3)];
[dragger setImage:[UIImage imageNamed:whichFlower]];
//add the new subview
[contentView addSubview:dragger];
[dragger release];
}
}
_(viod) dealloc
{
[contentView release];
[super dealloc];
}
@end