网易新闻主页头部

阅读: 评论:0

网易新闻主页头部

网易新闻主页头部

- (void)viewDidLoad
{[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.itemDataArray = [[NSMutableArray alloc] init];for (int i = 0 ; i< MAX_ITEM;i++) {NSString *itemStr = [NSString stringWithFormat:@"第%d个",i];[itemDataArray addObject:itemStr];}currentIndex = 0;itemScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];itemScrollView.backgroundColor = [UIColor redColor];[itemScrollView setShowsHorizontalScrollIndicator:NO];[itemScrollView setBounces:NO];itemScrollView.delegate = self;itemScrollView.tag = 11;[self.view addSubview:itemScrollView];tSize = CGSizeMake(ITEM_WIDTH*[itemDataArray count], 40);for (int i = 0; i< [itemDataArray count]; i++) {UILabel *labtitle = [[UILabel alloc] initWithFrame:CGRectMake(i*ITEM_WIDTH, 5, ITEM_WIDTH-4, 30)]; = [itemDataArray objectAtIndex:i];labtitle.font = [UIFont systemFontOfSize:14];labtitle.backgroundColor = [UIColor clearColor];[labtitle setTextAlignment:NSTextAlignmentCenter];[itemScrollView addSubview:labtitle];UIButton *bt = [[UIButton alloc] initWithFrame:CGRectMake(i*ITEM_WIDTH, 5, ITEM_WIDTH-4, 30)];bt.tag = 1000+i;        [bt addTarget:self action:@selector(itemPressed:) forControlEvents:UIControlEventTouchUpInside];[itemScrollView addSubview:bt];}itemBottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 38, ITEM_WIDTH, 2)];itemBottomLabel.backgroundColor = [UIColor blackColor];[itemScrollView addSubview:itemBottomLabel];UILabel *labname = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 100, 40)]; = [itemDataArray objectAtIndex:0];labname.tag = 100;[self.view addSubview:labname];UISwipeGestureRecognizer *panSwipeLeft  = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @selector(leftPanSwipe:)];UISwipeGestureRecognizer *panSwipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @selector(rightPanSwipe:)];[self.view addGestureRecognizer: panSwipeLeft];[self.view addGestureRecognizer: panSwipeRight];panSwipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;panSwipeRight.direction = UISwipeGestureRecognizerDirectionRight;
}


//右划
-(void)rightPanSwipe:(UISwipeGestureRecognizer *)gestureRecognizer{NSLog(@"right");if (currentIndex > 0) {currentIndex--;int itag = currentIndex;[UIView animateWithDuration:0.2 animations:^{itemBottomLabel.frame = CGRectMake(itag*ITEM_WIDTH, 38, ITEM_WIDTH, 2);} completion:^(BOOL finished) {UILabel *lab = (UILabel *)[self.view viewWithTag:100]; = [itemDataArray objectAtIndex:currentIndex];}];UIScrollView *s = (UIScrollView *)[self.view viewWithTag:11];if (s.contentOffset.x > currentIndex * ITEM_WIDTH) {[s  setContentOffset:CGPointMake(ITEM_WIDTH*currentIndex, 0) animated:YES];}}
}//获取类型
-(void)itemPressed:(UIButton *)sender
{int index = [sender tag];int itag = index - 1000;currentIndex = itag;[UIView animateWithDuration:0.2 animations:^{itemBottomLabel.frame = CGRectMake(itag*ITEM_WIDTH, 38, ITEM_WIDTH, 2);} completion:^(BOOL finished) {UILabel *lab = (UILabel *)[self.view viewWithTag:100]; = [itemDataArray objectAtIndex:currentIndex];}];
}


网易新闻主页头部

本文固定链接: /?p=3815 | 掌中天际


本文发布于:2024-02-02 12:59:46,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170684998743962.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:头部   网易新闻   主页
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23