Iphone UIScrollView按钮分页

Iphone UIScrollView按钮分页,iphone,uiscrollview,uibutton,uistoryboard,Iphone,Uiscrollview,Uibutton,Uistoryboard,我一直在尝试制作一个100x100像素的滚动视图(分页模式),每页显示一个75x75的按钮。我可以看到第一张图片,但无法转到下一张。这是我一直在使用的代码,有人能帮我吗 h m @菜单; -(无效)viewDidLoad{ scrollMenu.PaginEnabled=是; NSInteger numberOfButtons=2; 对于(int i=0;i

我一直在尝试制作一个100x100像素的滚动视图(分页模式),每页显示一个75x75的按钮。我可以看到第一张图片,但无法转到下一张。这是我一直在使用的代码,有人能帮我吗

h

m

@菜单;
-(无效)viewDidLoad{
scrollMenu.PaginEnabled=是;
NSInteger numberOfButtons=2;
对于(int i=0;i
除了UIImageView之外,我还实现了类似的功能。在这里,您只需要设置UI ScrollView的一些属性,并需要实现一个委托方法

首先设置一些属性

- (void)viewDidLoad
{
    [super viewDidLoad];

    _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    _scrollView.multipleTouchEnabled=YES;
    _scrollView.scrollEnabled=YES;
    _scrollView.directionalLockEnabled=YES;
    _scrollView.canCancelContentTouches=YES;
    _scrollView.delaysContentTouches=YES;
    _scrollView.clipsToBounds=YES;
    _scrollView.alwaysBounceHorizontal=YES;
    _scrollView.bounces=YES;
    _scrollView.pagingEnabled=YES;
    _scrollView.showsVerticalScrollIndicator=NO;
    _scrollView.showsHorizontalScrollIndicator=NO;
    _scrollView.delegate=self;

}
实现委托方法

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    @try
    {
        CGFloat pageWidth = 320;    //scrollView.frame.size.width;
        int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

        if (page >9)
            page = page - 3;
        if (page <[listOfPictures count])
        {
            [_scrollView setContentOffset:CGPointMake(320*page, _scrollView.contentOffset.y) animated:YES];
            currentPicIndex = page;
        }

    }
    @catch (NSException *exception)
    {
        TRACE_ERROR(@"scrollViewDidEndDecelerating", exception.name, exception.description);
    }

}
-(无效)ScrollViewDiEndDecelling:(UIScrollView*)scrollView
{
@试一试
{
CGFloat pageWidth=320;//scrollView.frame.size.width;
int page=floor((scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1;
如果(第9页)
第页=第3页;

如果(页面),谢谢,但我不认为这是我要找的。
- (void)viewDidLoad
{
    [super viewDidLoad];

    _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    _scrollView.multipleTouchEnabled=YES;
    _scrollView.scrollEnabled=YES;
    _scrollView.directionalLockEnabled=YES;
    _scrollView.canCancelContentTouches=YES;
    _scrollView.delaysContentTouches=YES;
    _scrollView.clipsToBounds=YES;
    _scrollView.alwaysBounceHorizontal=YES;
    _scrollView.bounces=YES;
    _scrollView.pagingEnabled=YES;
    _scrollView.showsVerticalScrollIndicator=NO;
    _scrollView.showsHorizontalScrollIndicator=NO;
    _scrollView.delegate=self;

}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    @try
    {
        CGFloat pageWidth = 320;    //scrollView.frame.size.width;
        int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

        if (page >9)
            page = page - 3;
        if (page <[listOfPictures count])
        {
            [_scrollView setContentOffset:CGPointMake(320*page, _scrollView.contentOffset.y) animated:YES];
            currentPicIndex = page;
        }

    }
    @catch (NSException *exception)
    {
        TRACE_ERROR(@"scrollViewDidEndDecelerating", exception.name, exception.description);
    }

}