2012-03-10 8 views
0

私はこのようなカスタムUIViewControllerを持っています。UIScrolllViewとinfo button

@implementation UIViewControllerCustom 


- (id)init 
{ 
    self = [super init]; 
    if (self) { 
     NSLog(@"init"); 
    } 

    return self; 
} 



-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
    [infoButton setFrame:CGRectMake(290, 10, 16, 16)]; 
    [infoButton addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:infoButton]; 
} 

-(void)showInfo 
{ 
    About *about = [[About alloc]init]; 
    NSLog(@"touched"); 
    [about setModalTransitionStyle:UIModalPresentationFullScreen]; 
    [self presentModalViewController:about animated:YES]; 
} 

@end 

私のアプリのすべてのビューコントローラはこのコントローラを継承します。情報ボタンがタッチされると、モーダルウィンドウが表示されます。問題は、私のView Controllerの1つがUIScrollViewを使用していることです。このコントローラでは、情報ボタンが表示され、タッチすると反応します。問題は、UIViewControllerCustomのボタンのshowInfoメソッドが呼び出されていないことです。他のコントローラーにはこのような問題はありません。 ここで何が間違っていますか?

答えて

1

UIScrollViewは送信されるメッセージを処理するためです。あなたの場合、ボタンのタッチはUIScrollViewによって処理されます。

UIScrollViewをサブクラス化して実装することをお勧めします。- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)viewを使用して、UIScrollViewがイベントを処理するかどうかを判断します。私はあなたが私が唯一scrollView内のボタンの制御を取得する提案コードを使用すると

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view { 
    if ([view isKindOfClass:[UIButton class]]) { 
     return NO; 
    } 

    return YES; 
} 
+0

実装はの線に沿って何かである可能性があります。私はまだ情報ボタンを制御することはできません。 – OhDoh

+0

ああ、あなたのUIViewControllerのビュープロパティはUIScrollViewだと分かりました。 UIScrollViewはUIViewControllerのself.viewのサブビューですか?それはあなたのUIButtonとのやりとりを止めるサブビューの順序ではないでしょうか?もしあなたがするなら、どうなるでしょう:[self.view sendSubviewToBack:scrollView];あなたのUIViewControllerで? –