NavigationController和scrollView的问题
来源:互联网 发布:淘宝心级怎么算买家 编辑:程序博客网 时间:2024/04/30 08:11
我把DiscoverController放在一个NavigationController里面然后再添加到tabbarcontroller里 然后我定义了一个scrollview 它的frame是 (0 0 self.view.frame.size.width, 108) (这里设置108是因为20是状态栏+44导航栏+44是我希望可以显示的scrollview的高度) 然后我添加一个UIView到scrollview上 这个uiview的frame是(100,0,500, 44). 我希望达到的效果是这个uiview只能左右滚动不能上下滚动所以我还设置了scrollview的contentsize是(900, 0). 但是很奇怪我添加了这个uiview之后还是能上下滚动 可是当我把scrollview的Y值设置为-5或者scrollview的height设置为49, 就变得只能左右滚动不能上下滚动 我想知道这个5是来自哪里的 为什么要把Y设置成-5才能达到只能左右不能上下滚动? 一般设置scrollview的滚动不是用contentsize 来决定的吗??
问题可能我没有说的很清楚 反正就是有5个pixel我不知道是从哪里来的 想求各位大神指教
代码如下:
#import "DiscoverController.h"
#import "DiscoverNaviButton.h"
#import "LocationController.h"
@interface DiscoverController () <UITableViewDataSource, UITableViewDelegate, LocationControllerDelegate>
@property(nonatomic, strong) LocationController *locationList;
@property(nonatomic, strong) DiscoverNaviButton *btn;
@property(nonatomic, weak) UIScrollView *typeScrollView;
@end
@implementation DiscoverController
- (LocationController *)locationList{
if(!_locationList){
_locationList = [[LocationController alloc] initWithStyle:UITableViewStylePlain];
UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[rightBtn setImage:[UIImage imageNamed:@"rightBtn"] forState:UIControlStateNormal];
rightBtn.bounds = CGRectMake(0, 0, 20, 20);
[rightBtn addTarget:self action:@selector(dismissVC) forControlEvents:UIControlEventTouchUpInside];
_locationList.delegate = self;
UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
_locationList.navigationItem.rightBarButtonItem = rightBarBtn;
_locationList.location = @"Toronto";
}
return _locationList;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
[self setupScrollViewBtn];
[self setupButtonTitle];
}
- (void)setupScrollViewBtn{
CGFloat scrollViewHeight = self.navigationController.navigationBar.frame.origin.y + self.navigationController.navigationBar.frame.size.height + 49;
UIScrollView *typeScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -5, self.view.frame.size.width, scrollViewHeight)];
typeScrollView.showsHorizontalScrollIndicator = NO;
typeScrollView.backgroundColor = [UIColor blueColor];
typeScrollView.contentSize = CGSizeMake(600, 0);
UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(100, 5, 400, 44)];
testView.backgroundColor = [UIColor yellowColor];
[typeScrollView addSubview:testView];
[self.view addSubview:typeScrollView];
}
- (void)setupButtonTitle{
DiscoverNaviButton *button = [[DiscoverNaviButton alloc] init];
button.frame = CGRectMake(0, 0, 80, 20);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitle:self.locationList.location forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"naviBtnArrow"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(presentVC) forControlEvents:UIControlEventTouchUpInside];
self.btn = button;
self.navigationItem.titleView = self.btn;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)presentVC{
UINavigationController *naviLocation = [[UINavigationController alloc] initWithRootViewController:self.locationList];
[self presentViewController:naviLocation animated:YES completion:nil];
}
- (void)dismissVC{
[self.locationList dismissViewControllerAnimated:YES completion:nil];
self.locationList = nil;
}
- (void)locationController:(LocationController *)locationController didSelectLocation:(NSString *)location{
[self setupButtonTitle];
[self.locationList dismissViewControllerAnimated:YES completion:nil];
self.locationList = nil;
}
- (void)changeType:(UIButton *)btn{
btn.selected = !btn.isSelected;
}
@end
问题可能我没有说的很清楚 反正就是有5个pixel我不知道是从哪里来的 想求各位大神指教
代码如下:
#import "DiscoverController.h"
#import "DiscoverNaviButton.h"
#import "LocationController.h"
@interface DiscoverController () <UITableViewDataSource, UITableViewDelegate, LocationControllerDelegate>
@property(nonatomic, strong) LocationController *locationList;
@property(nonatomic, strong) DiscoverNaviButton *btn;
@property(nonatomic, weak) UIScrollView *typeScrollView;
@end
@implementation DiscoverController
- (LocationController *)locationList{
if(!_locationList){
_locationList = [[LocationController alloc] initWithStyle:UITableViewStylePlain];
UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[rightBtn setImage:[UIImage imageNamed:@"rightBtn"] forState:UIControlStateNormal];
rightBtn.bounds = CGRectMake(0, 0, 20, 20);
[rightBtn addTarget:self action:@selector(dismissVC) forControlEvents:UIControlEventTouchUpInside];
_locationList.delegate = self;
UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
_locationList.navigationItem.rightBarButtonItem = rightBarBtn;
_locationList.location = @"Toronto";
}
return _locationList;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
[self setupScrollViewBtn];
[self setupButtonTitle];
}
- (void)setupScrollViewBtn{
CGFloat scrollViewHeight = self.navigationController.navigationBar.frame.origin.y + self.navigationController.navigationBar.frame.size.height + 49;
UIScrollView *typeScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -5, self.view.frame.size.width, scrollViewHeight)];
typeScrollView.showsHorizontalScrollIndicator = NO;
typeScrollView.backgroundColor = [UIColor blueColor];
typeScrollView.contentSize = CGSizeMake(600, 0);
UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(100, 5, 400, 44)];
testView.backgroundColor = [UIColor yellowColor];
[typeScrollView addSubview:testView];
[self.view addSubview:typeScrollView];
}
- (void)setupButtonTitle{
DiscoverNaviButton *button = [[DiscoverNaviButton alloc] init];
button.frame = CGRectMake(0, 0, 80, 20);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitle:self.locationList.location forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"naviBtnArrow"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(presentVC) forControlEvents:UIControlEventTouchUpInside];
self.btn = button;
self.navigationItem.titleView = self.btn;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)presentVC{
UINavigationController *naviLocation = [[UINavigationController alloc] initWithRootViewController:self.locationList];
[self presentViewController:naviLocation animated:YES completion:nil];
}
- (void)dismissVC{
[self.locationList dismissViewControllerAnimated:YES completion:nil];
self.locationList = nil;
}
- (void)locationController:(LocationController *)locationController didSelectLocation:(NSString *)location{
[self setupButtonTitle];
[self.locationList dismissViewControllerAnimated:YES completion:nil];
self.locationList = nil;
}
- (void)changeType:(UIButton *)btn{
btn.selected = !btn.isSelected;
}
@end
0 0
- NavigationController和scrollView的问题
- 关于设置navigationController title 和 TabBarController title 的问题
- io7,io8中关于scrollView在navigationController中的偏移问题
- UINavigationController和scrollview的问题
- 修改navigationController的背景色和隐藏navigationController下黑线
- navigationController导航隐藏和显示问题
- iOS - NavigationController经常出现的问题
- iOS使用NavigationController经常出现的问题
- tabbarcontroller+navigationcontroller 导航栏错乱的问题
- iOS使用NavigationController经常出现的问题
- 关于Listview和ScrollView的共存问题
- ScrollView和ListView一起使用的问题
- scrollview和viewpager嵌套冲突的问题
- ScrollView和ViewPager嵌套的问题
- 解决listView和scrollView的共存问题
- ScrollView 和 ListView ,GridView的嵌套问题
- listview 和 scrollview 冲突的问题
- listView 和 scrollView嵌套的问题
- linux上安装phpstudy
- 本地缓存
- rc/dc 工具报错的解决方案
- Java折半查找法代码
- PHP7 编译自带的扩展库
- NavigationController和scrollView的问题
- Android功能引导页的实现
- 算法---分类算法之贝叶斯分类
- GitHub for Windows 2.0使用教程
- eclispe工程没有编译的解决办法
- 深度学习-网络Xavier初始化方法
- git代码统计-生成详细html报告
- Metal Performance Shader使用小结
- jQuery和jquerymobile 实现火车票查询