gpt4 book ai didi

iphone - UIPageControl——点击点时 View 没有改变

转载 作者:可可西里 更新时间:2023-11-01 03:31:28 42 4
gpt4 key购买 nike

我在我的应用程序中使用了 pageControl。单击点时 View 不会更改,但在 pageControl 的两端,当我单击 View 时 View 正在更改。我希望他们在点击点时改变。该怎么办?我需要实现什么方法吗?

这是代码

#import "ScrollingViewController.h"

@implementation ScrollingViewController
@synthesize scrollView;
@synthesize pageControl;

- (void)viewDidLoad
{
[super viewDidLoad];
[self setupPage];
pageControl =[[UIPageControl alloc] initWithFrame:CGRectMake(0,390,320,100)];
pageControl.userInteractionEnabled =YES;
pageControl.numberOfPages = 5;
pageControl.currentPage = 0;
[self.pageControl setBackgroundColor:[UIColor blackColor]];
pageControl.enabled = TRUE;
[pageControl setHighlighted:YES];
[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:pageControl];
}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

- (void)viewDidUnload
{
[scrollView release];
[pageControl release];
}


- (void)dealloc
{
[super dealloc];
}


- (void)setupPage
{
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,400)];
[scrollView setContentSize:CGSizeMake(1000, 800)];
//scrollView.contentSize = CGSizeMake(1000,800);
scrollView.scrollsToTop = NO;
[self.scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;

NSUInteger nimages = 0;
CGFloat cx = 0;
for (; ; nimages++)
{
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", (nimages + 1)];
UIImage *image = [UIImage imageNamed:imageName];
if (image == nil)
{
break;
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

CGRect rect = imageView.frame;
rect.size.height = image.size.height;
rect.size.width = image.size.width;
rect.origin.x = ((scrollView.frame.size.width - image.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - image.size.height) / 2);

imageView.frame = rect;

[scrollView addSubview:imageView];
[imageView release];

cx += scrollView.frame.size.width;
}

self.pageControl.numberOfPages = nimages;
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
scrollView.delegate = self;
[self.view addSubview:scrollView];
}


- (void)scrollViewDidScroll:(UIScrollView *)_scrollView
{
if (pageControlIsChangingPage)
{
return;
}


CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView
{
pageControlIsChangingPage = NO;
}



- (IBAction)changePage:(id)sender
{
/*
* Change the scroll view
*/
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * pageControl.currentPage;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];
pageControlIsChangingPage = YES;
}

@end

最佳答案

尽量增加页面控件的宽度。即使您将页面控件的宽度保持得足够短以使其无法容纳尽可能多的点,它也可以显示它们。但是没有收到 Action 。

关于iphone - UIPageControl——点击点时 View 没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5977290/

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