-1

ジョイスティックとして使用したいUIボタンがあります。だから私は同じボタンにいくつかのジェスチャー認識機能を追加しようとしています。私は今私のコードにこれを持っています:

@implementation CUETutorialSixteenClusterRootController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:@"CUETutorialLandscapeClusterRootController" bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)init {
    self = [super init];
    if (self) {
        _leftInActiveView = [[NSMutableArray alloc] init];
        _rightInActiveViews = [[NSMutableArray alloc] init];
        _centerInActiveViews = [[NSMutableArray alloc]init];
        _centerActiveViews = [[NSMutableArray alloc]init];

        UIImageView * inActLeftView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 82, 98)] autorelease];
        inActLeftView.image = [UIImage imageNamed:@"1-am-station_01.png"];
        [_leftInActiveView addObject:inActLeftView];


        UIImageView * inActRightView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 82, 98)] autorelease];
        inActRightView.image = [UIImage imageNamed:@"1-am-station_03.png"];
        [_rightInActiveViews addObject:inActRightView];

        NSArray * imagesName = [NSArray arrayWithObjects:[UIImage imageNamed:@"1_start.png"],
                                [UIImage imageNamed:@"2_apptray_audio_selected.png"],
                                [UIImage imageNamed:@"2_apptray_phone_selected.png"],
                                [UIImage imageNamed:@"4_phonemenu_contacts_highlighted.png"],
                                [UIImage imageNamed:@"5_phonemenu_recentcalls_highlighted.png"],
                                [UIImage imageNamed:@"6_recent_calls.png"],
                                [UIImage imageNamed:@"7_bottom_hit.png"],
                                [UIImage imageNamed:@"8_recent_call_details.png"],
                                [UIImage imageNamed:@"9_calling.png"],
                                [UIImage imageNamed:@"9_calling_myphone.png"],
                                [UIImage imageNamed:@"9_call_ended.png"],nil];
        NSLog(@"Count:%d",[imagesName count]);
        for (int i =0; i<11; i++) {
            UIImageView * inActCenterView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 226, 98)] autorelease];
            inActCenterView.image = [imagesName objectAtIndex:i];
            [_centerActiveViews addObject:inActCenterView];
            [_centerInActiveViews addObject:inActCenterView];
        }
    }
    return self;
}

-(void)showClusterType:(clusterType)cluster{
    switch (cluster) {
            //Base Cluster is analog
        case kClusterTypeBase:
        {
            [self.fullClusterContainerView removeFromSuperview];
            [self.view addSubview:self.baseClusterContainerView];
            [self.view addSubview:self.baseClusterImageView];

            CUETutorialSixteenAplicationHomeScreen * clusAppScreen = [[CUETutorialSixteenAplicationHomeScreen alloc] initWithDelegate:self];
            clusAppScreen.dataSource = self;
            clusAppScreen.rootController = self;

            self.clusterHomeScreen = clusAppScreen;

            [self.baseClusterContainerView addSubview:clusAppScreen.view];
            [clusAppScreen release];

            /*
             [self.view bringSubviewToFront:self.steeringWheelImageView];
             [self.view bringSubviewToFront:self.promptLabel];
             [self.view bringSubviewToFront:[self.view viewWithTag:kFavDownButton]];
             [self.view bringSubviewToFront:[self.view viewWithTag:kFavUpButton]];
             [self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonUp]];
             [self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonLeft]];
             [self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonRight]];
             [self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonDown]];
             [self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonCenter]];
             */

            [self.view bringSubviewToFront:self.promptLabel];
        }
            break;
            //Full cluster is digital 
        case kClusterTypeFull:
        {
            [self.baseClusterImageView removeFromSuperview];
            [self.baseClusterContainerView removeFromSuperview];
            [self.view addSubview:self.fullClusterContainerView];

        }
            break;
        default:
            break;
    }
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

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


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    _step =1;
    UISwipeGestureRecognizer *recognizer;

    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [self.gestureRecieverButton addGestureRecognizer:recognizer];
    [recognizer release];
    recognizer = nil;

    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
    [self.gestureRecieverButton addGestureRecognizer:recognizer];
    [recognizer release];
    recognizer = nil;

    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    [self.gestureRecieverButton addGestureRecognizer:recognizer];
    [recognizer release];
    recognizer = nil;

    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [self.gestureRecieverButton addGestureRecognizer:recognizer];
    [recognizer release];
    recognizer = nil;


}

- (void)viewDidUnload
{
    [super viewDidUnload];
    time=0;

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
-(void)dealloc{
    [super dealloc];
    [_leftInActiveView release];
    [_rightInActiveViews release];
    [_centerActiveViews release];
    [_centerInActiveViews release];
}

-(void)animateToView:(UIView *)aview{
    if(aview){
        //CGRect rect = [aview convertRect:aview.bounds toView:self.view];
        CGRect rect = aview.frame;
        [self animateHandFromRect:self.promptLabel.frame toRect:rect];
    }
    else{
        [self animateHandToNSValueRect:nil];
    }
}

-(void)finishTutorial{
    [self displayPromptText:@"TUTORIAL COMPLETE"];
    [self displayNavigationBarWithTitle:@"TUTORIAL COMPLETE"];

    [self performBlock:^{
        [self.clusterHomeScreen.view removeFromSuperview];
        [self showScoresScreen];
    }afterDelay:1];
}
-(void)animateHandToCenterButton
{
    [self displayPromptText:@"TAP RIGHT SIDE CENTER BUTTON"];
    [self displayNavigationBarWithTitle:@"TAP RIGHT SIDE CENTER BUTTON"];
    [self animateToView:self.rCenterButton];
}
-(void)animateHandToDownButton {
    [self displayPromptText:@"TAP RIGHT SIDE DOWN BUTTON"];
    [self displayNavigationBarWithTitle:@"TAP RIGHT SIDE DOWN BUTTON"];
    [self animateToView:self.rDownButton];

}

-(void)animateHandToUpButton{
    [self displayPromptText:@"TAP RIGHT SIDE UP BUTTON"];
    [self displayNavigationBarWithTitle:@"TAP RIGHT SIDE UP BUTTON"];
    [self animateToView:self.rUpButton];

}

-(void)replaceCallScreen{
    [self performBlock:^{
        [self pressedRightButtonCenter];
    } afterDelay:2.0];

}

-(void)changeTimer {
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startTicking) userInfo:nil repeats:YES];

}

-(void)startTicking {
    time = time +1;
    self.clusterHomeScreen.callTimer.text = [NSString stringWithFormat:@"00:0%d",time];
    if (time==9) {
        [timer invalidate];
    }
}
-(void) animateHandToVolUpButton {
    [self displayPromptText:@"TAP VOLUME UP BUTTON"];
    [self displayNavigationBarWithTitle:@"TAP VOLUME UP BUTTON"];
    [self animateToView:self.rVolUpButton];

}

-(void) animateHandToVolDownButton {
    [self displayPromptText:@"TAP VOLUME DOWN BUTTON"];
    [self displayNavigationBarWithTitle:@"TAP VOLUME DOWN BUTTON"];
    [self animateToView:self.rVolDownButton];
}

-(void)removeVolumeView {
    [self pressedRightButtonCenter];
    [self.clusterHomeScreen runNextStep];
}

-(void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
    NSLog(@"Swipe received.%@",recognizer);
}

-(IBAction)buttonClicked:(id)sender
{    
    if ([sender tag]==kRightButtonDown && _step ==1)
    {
        [self pressedRightButtonDown];
        [self displayPromptText:@"TAP AGAIN"];
        [self displayNavigationBarWithTitle:@"TAP AGAIN"];
        _step++;
    }
    else if ([sender tag]==kRightButtonDown && _step == 2)
    {
        [self pressedRightButtonDown];
        [self animateToView:self.rCenterButton];
        [self displayPromptText:@"TAP CENTER BUTTON"];
        [self displayNavigationBarWithTitle:@"TAP CENTER BUTTON"];
        _step++;
    }
    else if ([sender tag]==kRightButtonCenter && _step == 3)
    {
        [self pressedRightButtonCenter];
        [self animateToView:self.rUpButton];
        _step++;
    }
    else if ([sender tag]==kRightButtonUp && _step == 4)
    {
        [self pressedRightButtonUp];
        [self displayPromptText:@"TAP CENTER BUTTON"];
        [self displayNavigationBarWithTitle:@"TAP CENTER BUTTON"];
        [self animateToView:self.rCenterButton];

        _step++;
    }

    else if ([sender tag]==kRightButtonCenter && _step==5){
        [self pressedRightButtonCenter];
        [self displayPromptText:@"TAP DOWN BUTTON"];
        [self displayNavigationBarWithTitle:@"TAP DOWN BUTTON"];
        [self animateToView:self.rDownButton];
        _step++;
    }
    else if([sender tag]==kRightButtonDown && _step==6){
        [self pressedRightButtonDown];
        [self animateToView:self.rCenterButton];
        [self displayPromptText:@"TAP CENTER BUTTON"];
        [self displayNavigationBarWithTitle:@"TAP CENTER BUTTON"];
        _step++;
    }
    else if ([sender tag]==kRightButtonCenter && _step==7){
        [self pressedRightButtonCenter];
        _step++;
    }
    else if ([sender tag]==kRightButtonCenter && _step==8)
    {
        [self pressedRightButtonCenter];
        self.clusterHomeScreen.callTimer.hidden = NO;
        [self.clusterHomeScreen runNextStep];
        _step++;
    }
    else if ([sender tag]==kRightButtonCenter && _step==9)
    {
        self.clusterHomeScreen.callTimer.hidden = YES;
        [self pressedRightButtonCenter];

        _step++;
    }
    else if ([sender tag]==kRightButtonCenter && _step==10)
    {
        [self pressedRightButtonCenter];
        [self finishTutorial];
    }
    else {
        [self displayVisualFeedback:kVisualFeedBackIncorrectAnswer];
    }
}


#pragma CUEClusterHomeSreenDataSource Methods
-(NSInteger)numberOfViewsForLeftScreen {

    return [_leftActiveViews count];
}
-(NSInteger)numberOfViewsForRightScreen{
    return [_rightActiveViews count];
}
-(NSInteger)numberOfViewsForCenterScreen {
    return [_centerActiveViews count];
}



-(UIImageView *)inActiveViewForLeftScreenAtIndex:(NSInteger)index{
    //if((index < [_leftInActiveView count]) && (index >=0)){
    return [_leftInActiveView objectAtIndex:index];
    //}
    //return nil;
}
-(UIImageView *)activeViewForLeftScreenAtIndex:(NSInteger)index{
    //  if((index < [_leftActiveViews count]) && (index >=0)){
    return [_leftActiveViews objectAtIndex:index];
    //}
    //return nil;
}
-(UIImageView *)inActiveViewForRightScreenAtIndex:(NSInteger)index{
    //if((index < [_rightInActiveViews count]) && (index >=0)){
    return [_rightInActiveViews objectAtIndex:index];
    //}
    //return nil;
}
-(UIImageView *)activeViewForRightScreenAtIndex:(NSInteger)index{
    //if((index < [_rightActiveViews count]) && (index >=0)){
    return [_rightActiveViews objectAtIndex:index];
    //}
    //return nil;
}

-(UIImageView *)inActiveViewForCenterScreenAtIndex:(NSInteger)index{
    //if((index < [_leftInActiveView count]) && (index >=0)){
    return [_centerInActiveViews objectAtIndex:index];
    //}
    //return nil;
}
-(UIImageView *)activeViewForCenterScreenAtIndex:(NSInteger)index{
    //  if((index < [_leftActiveViews count]) && (index >=0)){
    return [_centerActiveViews objectAtIndex:index];
    //}
    //return nil;
}

これは私が今得ているエラーです:-[CUETutorialSixteenClusterRootController handleSwipeFrom:]:認識されないセレクターがインスタンス0x79b71b0に送信されました2012-03-28 13:25:55.724 CUETrainer [1788:11f03] *キャッチされない例外のためにアプリを終了します' NSInvalidArgumentException'、理由:'-[CUETutorialSixteenClusterRootController handleSwipeFrom:]:認識されないセレクターが送信されましたインスタンス0x79b71b0 '

しかし、実際には何もしていません。助けてください!!!!

4

3 に答える 3

1

ジェスチャレコグナイザのターゲットは、セレクタを実装するオブジェクトである必要があります。スワイプが発生したときに今起こっていることは、ジェスチャレコグナイザーが実行していることです[self.gestureReceiverButton handleSwipeFrom:recognizer]

あなたはおそらくこれが欲しいでしょう:

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
于 2012-03-28T17:07:28.897 に答える
1

エラーはunrecognized selector sent to instance 0x79b71b0'、おそらく.hと.mの名前が異なることを示しています。

于 2012-03-28T18:01:53.513 に答える
0

次のすべてのインスタンスを変更します。

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];

問題が解決しました。に十分注意してください@selectors。このマクロに配置する内容は、コンパイラによって検証されません。コードコンプリートはこれに役立ちます。

また、1つのビューに4つのジェスチャ認識機能を追加しますが、1つで同じタスクを実行できます。次のように、ビットごとのOR演算子を使用して有効な方向を組み合わせることができます。

[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown)];

于 2012-03-28T18:26:57.880 に答える