我正在使用CPJoystick,可在此处找到。 https://github.com/Wense/CPJoystick
我正在使用Xcode 4.6,断点在那里停止。
@property (nonatomic, weak, readwrite) id<CPJoystickDelegate> delegate;
所以我做了一些改变。我已经下载了数百名代表,甚至尝试过这个代理:Custom delegate not working
我尝试了很多:
@property (nonatomic, strong, readwrite) id<CPJoystickDelegate> delegate;
@property (nonatomic, strong) id<CPJoystickDelegate> delegate;
@property (nonatomic, retain) id<CPJoystickDelegate> delegate;
@property(nonatomic,assign)id delegate;
我不明白我在做什么。我困住了五个星期,感到很困惑。
CPJoystick.h
@protocol CPJoystickDelegate <NSObject>
@required
- (void) ShowthisNumbers:(NSString*)text;
@optional
// - (void) ShowthisNumbers:(NSString*)text;
-(void)cpJoystick:(CPJoystick *)aJoystick didUpdate:(CGPoint)movement;
@end
CPJoystick.m
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
...
[delegate ControlPosition:@"Touched"];
}
我甚至无法让这件事在UIViewController上与UILabel进行通信&lt; CPJoystickDelegate&gt; 操纵杆似乎工作正常,但UILabel无法正常工作。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
CPJoystick *joystick = [[CPJoystick alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[joystick setThumbImage:[UIImage imageNamed:@"handleImage.png"] andBGImage:[UIImage imageNamed:@"bgImage.png"]];
[joystick setMovementUpdateInterval:1.0/30];
[self.iSneaky addSubview:joystick];
[joystick setMoveViscosity:4 andSmallestValue:0.09]; //defaults are 7 and 0.09
}
-(void)ControlPosition:(NSString*)text;
{
amountLabel.text = text;
}
-(void)cpJoystick:(CPJoystick *)aJoystick didUpdate:(CGPoint)movement
{
NSLog(@"x = %f",movement.x);
NSLog(@"y = %f",movement.y);
character.center = CGPointMake(character.center.x + movement.x, character.center.y + movement.y);
}
任何人都可以帮助我....我需要一些新鲜空气。
答案 0 :(得分:0)
您的viewDidLoad
方法似乎没有设置代表。
CPJoystick *joystick = [[CPJoystick alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[joystick setThumbImage:[UIImage imageNamed:@"handleImage.png"] andBGImage:[UIImage imageNamed:@"bgImage.png"]];
[joystick setMovementUpdateInterval:1.0/30];
[self.iSneaky addSubview:joystick];
[joystick setMoveViscosity:4 andSmallestValue:0.09]; //defaults are 7 and 0.09
joystick.delegate = self;