salut j'essayais de compléter un iphone projct à partir du livre de recettes des développeurs iphone sur les vues déplaçables coupées et j'avais du mal à savoir quels segments de code va dans quel fichier iv été déconner quelque temps avec maintenant tout organisme peut me donner une certaine direction Heres le codequel code va où pour un projet 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
et
/*
*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