2009-09-19 3 views
0

привет, я пытался завершить iphone projct из кулинарной книги разработчиков iphone по перетаскиваемым просмотрам, обрезанным, и у меня была сложная разработка, какие сегменты кода входят в какой файл iv время от времени возится с теперь любой орган может дать мне направление Heres кодкакой код идет, где для проекта 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 

ответ

1

Я хотел бы предложить первый собирается пример кода Apple, и загрузив пример проекта. Потратьте немного времени на выяснение того, как это работает, измените код и посмотрите, как он влияет на приложение. Это научит вас, как собрать приложение. Если вы научите человека, как ловить рыбу ...

1

Похоже, вы захотите создать «DragView.h» и «DragView.m».

Раздел @interface переходит в DragView.h, а раздел @implementation переходит в DragView.m.

В вашем HelloController вам нужно добавить вверху: #include "DragView.h".

Смежные вопросы