简单实现滑动和点击翻页 button与scrollView结合 iOS
来源:互联网 发布:windows rt怎么换系统 编辑:程序博客网 时间:2024/06/07 02:36
//
// ViewController.m
// 第一天的
//
// Created by beevle on 16/1/11.
// Copyright © 2016年 beevle. All rights reserved.
//
#import "ViewController.h"
#define WW_width [UIScreen mainScreen].bounds.size.width
#define WW_height [UIScreen mainScreen].bounds.size.height
@interface ViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
@end
@implementation ViewController
{
UIButton * _lastBtn;
UIScrollView * _scrollView;
UITableView * _tableView;
}
- (void)viewDidLoad {
[superviewDidLoad];
[selfcreateNAV];
[self createScrollView];
}
//导航
- (void)createNAV{
UIView * topview = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 375,64)];
topview.userInteractionEnabled =YES;
topview.backgroundColor = [UIColorgrayColor];
NSArray * nameArr =@[@"日",@"周",@"月"];
for (int i =0; i<3; i++) {
UIButton * button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(100+i*50,20, 30,30);
[button setTitle:nameArr[i] forState:UIControlStateNormal];
[button setTitleColor:[UIColorblackColor] forState:(UIControlStateSelected)];
button.tag =100 + i;
if (button.tag ==100) {
button.selected =YES;
_lastBtn = button;
}
[topview addSubview:button];
[button addTarget:selfaction:@selector(buttonClick:)forControlEvents:UIControlEventTouchUpInside];
}
[self.viewaddSubview:topview];
}
//点击事件
-(void)buttonClick:(UIButton *)btn{
if (btn!=_lastBtn) {
btn.selected =YES;
_lastBtn.selected =NO;
_lastBtn =btn;
[UIViewanimateWithDuration:0.5animations:^{
_scrollView.contentOffset =CGPointMake((btn.tag-100)*WW_width,0);
}];
}
}
//主要效果
-(void)createScrollView {
_scrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(0,64, WW_width,WW_height)];
_scrollView.autoresizesSubviews=NO;
_scrollView.backgroundColor = [UIColorwhiteColor];
_scrollView.contentSize =CGSizeMake([UIScreenmainScreen].bounds.size.width*3,WW_height-64) ;
_scrollView.pagingEnabled =YES;
_scrollView.delegate =self;
for (int i =0 ; i<3; i++) {
UIView * view = [[UIViewalloc]initWithFrame:CGRectMake(i*WW_width,0, WW_width,WW_height-64)];
view.tag =200 + i ;
if (view.tag==200) {
view.backgroundColor = [UIColorgreenColor];
}elseif (view.tag ==201){
view.backgroundColor = [UIColoryellowColor];
}else{
view.backgroundColor = [UIColorcyanColor];
}
[_scrollViewaddSubview:view];
}
[self.viewaddSubview:_scrollView];
}
//scrollview 的协议方法
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
float sub =_scrollView.contentOffset.x/WW_width;
UIButton * btn = (UIButton * )[self.viewviewWithTag:100+sub];
if (_lastBtn != btn) {
btn.selected =YES;
_lastBtn.selected =NO;
_lastBtn =btn;
}
}
@end
- 简单实现滑动和点击翻页 button与scrollView结合 iOS
- 简单的实现Scrollview点击左右滑动
- IOS--UiScrollView和UIPageControl实现滑动翻页
- 手势GestureDetector与ViewFlipper结合使用,实现滑动翻页
- iOS viewDeck和scrollView结合实现的侧滑栏(仿网易)
- Android提高篇之listView点击button翻页功能实现
- IOS button翻页
- Fragment与ViewPager实现页面滑动翻页
- 仿微信滑动翻页UI设计和实现
- 仿微信滑动翻页UI设计和实现
- iOS 在tableView上添加button导致按钮没有点击效果和不能滑动的问题
- scrollview上添加button 滑动botton区域无法实现scrollview滑动的解决方法
- iOS实现左右循环滑动ScrollVIew
- iOS实现左右循环滑动ScrollVIew
- 安卓实现点击Button和滑动SeekBar发送数据到服务端
- ScrollView滚动层容器与button点击事件
- scrollView中放满button,无法滑动
- ViewFlipper实现滑动翻页
- ios开发使用UIWebView显示多种文档
- SVD原理及其应用导论
- js XMLHttprequest
- 无需翻墙打开谷歌与谷歌学术的链接
- OpenWrt下ifconfig各接口说明
- 简单实现滑动和点击翻页 button与scrollView结合 iOS
- Android:验证手机和邮箱的正则表达式
- android调试debug快捷键
- css选择元素时有没有空格的区别
- 欢迎使用CSDN-markdown编辑器
- Gradle学习笔记(五)
- Visual Studio序列号
- JAVA线程基础
- git与github常用指令--学习笔记