В моем приложении я реализую действительно сложное управление, основанное на ARScrollViewEnhancer
. Мне нужно это для отображения нескольких страниц UIScrollView
. Так что это мой код UIScrollView
:UIButton как subview на сложном UIScrollView
dateScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(28, 0, dateLabelMaxSize, 45)];
dateScroll.pagingEnabled = YES;
dateScroll.clipsToBounds = NO;
dateScroll.showsHorizontalScrollIndicator = NO;
dateScroll.backgroundColor = [UIColor clearColor];
dateScroll.contentSize = CGSizeMake(dateLabelMaxSize*[dayArray count], 45);
Я использую dateScroll.clipsToBounds = NO;
для отображения страниц из кадра. Это код ARScrollViewEnhancer
:
ARScrollViewEnhancer *backForDate = [[ARScrollViewEnhancer alloc] initWithFrame:CGRectMake(0, 80, self.view.frame.size.width, 45)];
[backForDate addSubview:dateScroll];
backForDate._scrollView = dateScroll;
[self.view addSubview:backForDate];
Затем я добавил подвидов для UIScrollView
. Это UILabels
и UIButtons
.
for (int i=0;i<[dayArray count];i++){
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(3+dateLabelMaxSize*i, 5, dateLabelMaxSize, 40)];
dateLabel.backgroundColor = [UIColor clearColor];
dateLabel.textAlignment = UITextAlignmentLeft;
dateLabel.text = @"some text...";
[dateScroll addSubview:dateLabel];
UIButton *dateButton = [UIButton buttonWithType:UIButtonTypeCustom];
//dateButton.backgroundColor = [UIColor redColor];
dateButton.frame = CGRectMake(3+dateLabelMaxSize*i, 5, dateLabelMaxSize-10, 40);
dateButton.tag = i;
[dateButton addTarget:self action:@selector(dateTapped:) forControlEvents:UIControlEventTouchUpInside];
[dateScroll addSubview:dateButton];
}
И метод для кнопки:?...
-(void)dateTapped:(UIButton*)button{
NSLog(@"%i",button.tag);
}
Так, кнопки не работали ((почему Thnx
UPD
Трассировка код Methode Был:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if ([self pointInside:point withEvent:event]) {
return _scrollView;
}
return nil;
}
Сейчас:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *scrv = _scrollView;
UIView *superView = [super hitTest:point withEvent:event];
if (superView == self)
{
CGPoint scrollViewpoint = [_scrollView convertPoint:point fromView:self];
for(UIView *view in _scrollView.subviews) {
if(CGRectContainsPoint(view.frame, scrollViewpoint)) {
return view;
}
}
return scrv;
}
return superView;
}
Вы должны установить ContentSize вашей точки зрения прокрутки – Mutawe
@Mutawe я сделал это. добавьте в мой код. dateScroll.contentSize = CGSizeMake (dateLabelMaxSize * [dayArray count], 45); –