什么代码去了iphone项目的哪个地方

时间:2009-09-19 05:36:10

标签: iphone cocoa-touch

嗨我试图从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

2 个答案:

答案 0 :(得分:1)

我建议先转到Apple示例代码并下载示例项目。花一点时间弄清楚它是如何工作的,改变一些代码并看看它如何影响应用程序。这将教你如何组合一个应用程序。如果你教男人如何钓鱼......

答案 1 :(得分:1)

看起来你想要创建“DragView.h”和“DragView.m”。

@interface部分进入DragView.h,@implementation部分进入DragView.m。

在HelloController中,您需要在顶部添加:#include "DragView.h"