嗨,我有uiscrollview和uipage控件,在uiscrollview我有按钮(自定义按钮)
并且coading如下
bodyView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,
0,
320,
415)];
bodyView.userInteractionEnabled = YES;
bodyView.pagingEnabled = YES;
bodyView.contentSize = CGSizeMake(640,self.bodyView.frame.size.height);
bodyView.showsHorizontalScrollIndicator = NO;
bodyView.scrollEnabled = YES;
bodyView.showsVerticalScrollIndicator = NO;
bodyView.scrollsToTop = NO;
bodyView.delegate = self;
bodyView.canCancelContentTouches = NO;
bodyView.delaysContentTouches = NO;
[self.view addSubview:self.bodyView];
pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0,425,320,10)];
pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = 0;
pageControl.userInteractionEnabled=YES;
pageControl.multipleTouchEnabled=YES;
[pageControl addTarget:self action:@selector(changePageNavigation) forControlEvents:UIControlEventTouchUpInside];
[pageControl addTarget:self action:@selector(changePageNavigation) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:pageControl];
[self.view bringSubviewToFront:bodyView];
- (void)createIcons{
buttonCustom = [self createDynamicCustomButtons:CGRectMake(12, 103, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/pharmacy.png")]
tag:1];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(12,185, 80, 13)
text:NSLocalizedString(@"pharmacyTitle",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(120, 103, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/photo.png")]
tag:2];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(116, 185,80, 13)
text:NSLocalizedString(@"photo Title",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(227, 103, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/store_locator.png")]
tag:3];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(225, 185, 80, 13)
text:NSLocalizedString(@"StoreTitle",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(12, 208, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/coupons.png")]
tag:12];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(23, 290, 60, 13)
text:NSLocalizedString(@"couponsTitle",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(120, 208, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/refill_by_scan.png")]
tag:6];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(116, 290, 89, 13)
text:NSLocalizedString(@"Refill Title",nil)];
[bodyView addSubview:labelCustom];
//buttonCustom = [self createDynamicCustomButtons:CGRectMake(224, 220, 65, 65)
// image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/65x65_weekly_ad.png")]
buttonCustom = [self createDynamicCustomButtons:CGRectMake(227, 208, 65, 62)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/multi_scan.png")]
tag:7];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(225, 290, 86, 13)
text:NSLocalizedString(@"scanner",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons: CGRectMake(12, 313, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/shopping_list.png")]
tag:9];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(15,395, 75, 13)
text:NSLocalizedString(@"ShoppinglistTitle",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(120, 313, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/weekly_ad.png")]
tag:8];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels: CGRectMake(120,395, 80, 13)
text:NSLocalizedString(@"Weeklyads title",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(227, 313, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/gift_finder.png")]
tag:nil];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(237, 395, 60, 13)
text:NSLocalizedString(@"giftFinder",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(333, 103, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/shop.png")]
tag:4];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(344, 185, 60, 13)
text:NSLocalizedString(@"shop",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(440, 103, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/find_a_clinic.png")]
tag:11];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(439, 185,80, 13)
text:NSLocalizedString(@"clinicTitle",nil)];
[bodyView addSubview:labelCustom];
buttonCustom = [self createDynamicCustomButtons:CGRectMake(547, 103, 65, 65)
image:[UIImage imageFromPath:TKBUNDLE(@"Images.bundle/Images/HomeScreen/settings.png")]
tag:10];
[bodyView addSubview:buttonCustom];
labelCustom = [self createDynamicCustomLabels:CGRectMake(558, 185, 60, 14)
text:NSLocalizedString(@"settingsTitle",nil)];
[bodyView addSubview:labelCustom];
}
//Begin - To create a icon's custom button ***Sujya***
-(UIButtonCustom *)createDynamicCustomButtons:(CGRect)frame image:(UIImage *)buttonImage tag:(int)tagValue
{
UIButtonCustom *customIconButton = [UIButtonCustom buttonWithType:UIButtonTypeCustom];
[customIconButton retain];
//customIconButton.buttonType =UIButtonTypeCustom;
[customIconButton setImage:buttonImage
forState:UIControlStateNormal];
[customIconButton addTarget:self
action:@selector(btnIconClicked:)
forControlEvents:UIControlEventTouchUpInside];
[customIconButton setTag:tagValue];
frame.size.width=buttonImage.size.width;
frame.size.height=buttonImage.size.height;
[customIconButton setFrame:frame];
return customIconButton;
}
我可以滚动视图而无需点击按钮但触摸按钮时我尝试滚动但无法滚动视图
任何人都可以告诉我如何滚动触摸按钮
答案 0 :(得分:0)
如果我理解正确,你想通过点击UIButton来滚动scrollView。
UIScrollView有一个方法
scrollRectToVisible:animated:
以滚动方式滚动滚动视图。
你可以试试这个:
-(IBAction)switchToPG2{
CGRect frame = self.scrollView.frame;
frame.origin.x = frame.size.width * 1;//or the index of the page that you want
self.pageControl.currentPage=1;
frame.origin.y = 0;
[self.scrollView scrollRectToVisible:frame animated:YES];
}
希望这有帮助。