通过触摸的图像移动不起作用

问题描述:

我在我的iPad应用程序中使用名为“ATrackThumb”的两个图像&“BTrackThumb”,以便通过用户的触摸来移动。我正在使用一些方法来达到这个目的。但图像移动不起作用。 方法有:通过触摸的图像移动不起作用

#pragma mark responding to touch events 

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{ 
    for (UITouch *touch in touches) { 
    CGPoint t = [touch locationInView:touch.view]; 
    if(t.x > (ATrackThumb.center.x-25) && t.x < (ATrackThumb.center.x+25) && t.y > (ATrackThumb.center.y-25) && t.y < (ATrackThumb.center.y+25)){ 
     ASliderLastTouch = touch; 
    } 
    if(t.x>(BTrackThumb.center.x-25) && t.x < (BTrackThumb.center.x+25) && t.y > (BTrackThumb.center.y-25) && t.y < (BTrackThumb.center.y+25)){ 
     BSliderLastTouch = touch; 
    } 
    } 
} 

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event{ 
    for (UITouch *touch in touches) { 
     CGPoint t = [touch locationInView:touch.view]; 
     //Check Slider for Contact 
     if(touch==ASliderLastTouch){ 
     if(t.x>205) 
      [ATrackThumb setCenter:CGPointMake(205,ATrackThumb.center.y)]; 
     else if(t.x<24) 
      [ATrackThumb setCenter:CGPointMake(24,ATrackThumb.center.y)]; 
     else 
      [ATrackThumb setCenter:CGPointMake(t.x,ATrackThumb.center.y)]; 

     hourSlider.value=(ATrackThumb.center.x-24)/15; 
     [self updateHour]; 
     } 
     if(touch==BSliderLastTouch){ 
     if(t.x>205) 
      [BTrackThumb setCenter:CGPointMake(205,BTrackThumb.center.y)]; 
     else if(t.x<24) 
      [BTrackThumb setCenter:CGPointMake(24,BTrackThumb.center.y)]; 
     else 
      [BTrackThumb setCenter:CGPointMake(t.x,BTrackThumb.center.y)]; 

     minutesSlider.value=(BTrackThumb.center.x-24)/3.0; 
     [self updateMinute]; 
     } 
    } 
} 
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{ 
    for (UITouch *touch in touches) { 
    if(touch==ASliderLastTouch)ASliderLastTouch=nil; 
    if(touch==BSliderLastTouch)BSliderLastTouch=nil; 
    } 
} 

问题在哪里?

+0

现在格式化。没有人想读这个烂摊子。 – 2013-02-09 09:28:37

下面的代码是用于移动图像上的触摸

AppDelegate Classes 

**// .h File** 

#import <UIKit/UIKit.h> 

@class UITouchTutorialViewController; 

@interface UITouchTutorialAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
    UITouchTutorialViewController *viewController; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet UITouchTutorialViewController *viewController; 

@end 

////////////////////////////////////////////////////////////////////////////////// 

// .m File 

#import "UITouchTutorialAppDelegate.h" 
#import "UITouchTutorialViewController.h" 

@implementation UITouchTutorialAppDelegate 

@synthesize window; 
@synthesize viewController; 


- (void)applicationDidFinishLaunching:(UIApplication *)application {  

    // Override point for customization after app launch  
    [window addSubview:viewController.view]; 
    [window makeKeyAndVisible]; 
} 


- (void)dealloc { 
    [viewController release]; 
    [window release]; 
    [super dealloc]; 
} 


@end 
////////////////////////////////////////////////////////////////////////////// 

UIViewController Classes 

// .h file 

#import <UIKit/UIKit.h> 

@interface UITouchTutorialViewController : UIViewController { 
    IBOutlet UIImageView *cloud; 
} 

@end 

// .m File 

#import "UITouchTutorialViewController.h" 

@implementation UITouchTutorialViewController 

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 
    cloud.center = location; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self touchesBegan:touches withEvent:event]; 
} 

/* 
// Override initWithNibName:bundle: to load the view using a nib file then perform additional customization that is not appropriate for viewDidLoad. 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
     // Custom initialization 
    } 
    return self; 
} 
*/ 

/* 
// Implement loadView to create a view hierarchy programmatically. 
- (void)loadView { 
} 
*/ 


/* 
// Implement viewDidLoad to do additional setup after loading the view. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
} 
*/ 


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 


- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview 
    // Release anything that's not essential, such as cached data 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end