gpt4 book ai didi

objective-c - uiscrollview 中的页面控件

转载 作者:太空狗 更新时间:2023-10-30 03:53:40 25 4
gpt4 key购买 nike

我已经创建了一个包含页面控件的 uiscrollview,它从资源包中加载图像。一切正常。我可以滚动浏览不同的图像。问题是如果我要单击相应的页面控件(点),我不会能够导航到相应的图像....你们能帮我解决下面的代码吗...下面的代码工作得很好

// Email.h

@interface Email : UIViewController<UIScrollViewDelegate>
{
UIPageControl *pageControl;
UIScrollView *scroller;
}

@property (nonatomic,retain)IBOutlet UIPageControl *pageControl;
@property (nonatomic,retain)IBOutlet UIScrollView *scroller;

-(IBAction)clickPageControl:(id)sender;

@end


// Email.m

@implementation Email
@synthesize pageControl,scroller;

-(IBAction)clickPageControl:(id)sender
{
int page=pageControl.currentPage;
CGRect frame=scroller.frame;
frame.origin.x=frame.size.width=page;
frame.origin.y=0;
[scroller scrollRectToVisible:frame animated:YES];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int page = scrollView.contentOffset.x/scrollView.frame.size.width;
pageControl.currentPage=page;
}

- (void)viewDidLoad
{
[super viewDidLoad];
self.title=@"Press Photos";
for (int i=1; i<10; i++)
{
UIImageView *images=[[UIImageView alloc]initWithImage:
[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]]];
images.frame=CGRectMake((i-1)*320, 0, 320, 460);
[scroller addSubview:images];
[images release];
}
scroller.delegate=self;
scroller.contentSize=CGSizeMake(320*9, 460);
scroller.pagingEnabled=YES;

pageControl.numberOfPages=9;
pageControl.currentPage=0;
}

最佳答案

frame.origin.x=frame.size.width=page;

应该是

frame.origin.x = frame.size.width * page;

关于objective-c - uiscrollview 中的页面控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6045262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com