0

iPad アプリケーションで「ATrackThumb」と「BTrackThumb」という名前の 2 つの画像を使用して、ユーザーのタッチで移動します。この目的のためにいくつかの方法を使用しています。しかし、画像の動きは機能していません。メソッドは次のとおりです。

#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;
  }
} 

問題はどこだ?

4

1 に答える 1

0

次のコードは、タッチで画像を移動するために使用されます

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
于 2013-02-09T09:46:18.657 に答える