简体   繁体   English

xcode 5水平滚动视图不起作用(iOS7)

[英]xcode 5 horizontal scrollview doesn't work (iOS7)

Im trying to create an filter bar with a horizontal scroll view. 我试图用水平滚动视图创建一个过滤器栏。 How can I create the horizontal scrollview in xcode 5 for iOS7? 如何在iOS 7的Xcode 5中创建水平滚动视图?

This is my code: 这是我的代码:

[self.scroll setScrollEnabled:YES];
[self.scroll setDelegate:self];
self.scroll.backgroundColor = [UIColor clearColor];
scroll.contentMode = UIViewContentModeScaleToFill;
[self.scroll setContentSize:CGSizeMake(320.0,143.0)];
[self.view addSubview:scroll];
[self.scroll setContentSize:CGSizeMake(320.0,143.0)];

For scroll view to scroll horizontally the width of the content size should be larger than the actual frame of scroll view. 为了使滚动视图水平滚动,内容大小的宽度应大于滚动视图的实际框架。

If your scroll view frame size is (320, 143), the width of content size of scroll view should be larger than 320 so that the scroll view scroll. 如果滚动视图的框架大小为(320,143),则滚动视图的内容大小的宽度应大于320,以便滚动视图滚动。

For horizontal scroll view you can use, EasyTableView . 对于水平滚动视图,可以使用EasyTableView Its simple to use. 使用简单。

You will need to get use to the facilities - the horizontal scrollview works and it works in different ways including simulating pages that you can flick right or left. 您将需要使用这些功能-水平滚动视图起作用,并且它以不同的方式起作用,包括模拟可以左右滑动的页面。

scrollview has a physical size (frame) and a content size, the thing with scrollviews is the content size will be larger than the physical dimensions so I can for example have a UIImageView of 930x 250 viewable in an iPhone with 320 x 480 scrollview有一个物理尺寸(框架)和一个内容尺寸,带有scrollviews的东西是内容尺寸将大于物理尺寸,因此,例如,我可以使UIImageView为930x 250,可在320 x 480的iPhone中查看

(I'll skip the rest of the setup - just what's essential - for all the other tricks look into the apple sample projects - there is a lot - Note also that a lot of apps just use the Interface Builder to paint the view with the scrollview ) (我将跳过其余的设置-必不可少的-对于其他所有技巧,请参见Apple示例项目-有很多-请注意,许多应用程序仅使用Interface Builder来绘制视图滚动视图

 UIScrollview *scroll = [[UIScrollview alloc] init] 

 scroll.frame = CGSizeMake (0,100,320,250);
 scroll.contentsize = CGSizeMake(930,250)     


  UIImageView *imageview = [[UIImageView alloc]init];
  imageview.image = myimage;  //(UIImage)

  [self.view addSubview:scroll];  // add subview as the bottom layer to the main view
  [scroll addSubview imageview];

Below is something more complex with pages: 以下是页面更复杂的内容:

         pagectrl.numberOfPages = 7;
pagectrl.currentPage = 0;

scrollView.pagingEnabled = YES;
scrollView.contentSize=CGSizeMake(320* pagectrl.numberOfPages, 500);
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.bouncesZoom = NO;
scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
scrollView.scrollsToTop = NO;


scrollView.delegate = self;
search_url.delegate = self;
user.delegate = self;
password.delegate = self;
rpc_code.delegate = self;


// add pages

int page = 0;

CGRect frame = scrollView.frame;
pagesize = frame.size.width;
frame.origin.y = 0;
frame.origin.x = frame.size.width * page;
firstView.frame = frame;
[scrollView addSubview:firstView];

page ++;
frame.origin.x = frame.size.width * page;
locsubView.frame = frame;
[scrollView addSubview:locsubView];

page ++;
frame.origin.x = frame.size.width * page;
QRgensubView.frame = frame;
[scrollView addSubview:QRgensubView];

page ++;
frame.origin.x = frame.size.width * page;
scansubView.frame = frame;
[scrollView addSubview:scansubView];

page ++;
frame.origin.x = frame.size.width * page;
symbologysubView.frame = frame;
[scrollView addSubview:symbologysubView];

page ++;
frame.origin.x = frame.size.width * page;
gaView.frame = frame;
[scrollView addSubview:gaView];

page ++;
frame.origin.x = frame.size.width * page;
upcsubView.frame = frame;
[scrollView addSubview:upcsubView];

[self registerForKeyboardNotifications];

if (gotopage == 7) {
    int xloc = ((gotopage - 1) * pagesize);
    CGRect fieldrect = CGRectMake(xloc,0,320, pagesize);

    [scrollView scrollRectToVisible:fieldrect animated:YES];

}    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM