Iphone UIPageControl错误:先显示一个项目符号,然后显示所有内容

Iphone UIPageControl错误:先显示一个项目符号,然后显示所有内容,iphone,sdk,uiscrollview,Iphone,Sdk,Uiscrollview,我使用UIPageControl时有一些奇怪的行为: 首先它只显示一个项目符号,然后当我移动滚动视图时,所有项目符号都正确显示。在将其添加为子视图之前,是否缺少某些内容 这是我的代码imageScrollView.h: @interface ImageScrollView : UIView <UIScrollViewDelegate> { NSMutableDictionary *photos; BOOL *pageControlIsChangingPage; UIPag

我使用UIPageControl时有一些奇怪的行为:

首先它只显示一个项目符号,然后当我移动滚动视图时,所有项目符号都正确显示。在将其添加为子视图之前,是否缺少某些内容

这是我的代码imageScrollView.h:

@interface ImageScrollView : UIView <UIScrollViewDelegate> {
  NSMutableDictionary *photos;
  BOOL *pageControlIsChangingPage;
  UIPageControl *pageControl;
}
@property (nonatomic, copy) NSMutableDictionary *photos; 
@property (nonatomic, copy) UIPageControl *pageControl; 
@end

由于您正在
drawRect
方法中绘制
UIPageControl
,因此需要在初始化该控件后调用该控件的
setNeedsLayout
方法。否则,在调用强制重画的事件之前,它将无法正确渲染自身

pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(self.frame.size.width/2,  self.frame.size.height -20, (self.frame.size.width/nimages)/2, 20)];
pageControl.numberOfPages=nimages;
[pageControl setNeedsLayout];
[self addSubview:pageControl];
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(self.frame.size.width/2,  self.frame.size.height -20, (self.frame.size.width/nimages)/2, 20)];
pageControl.numberOfPages=nimages;
[pageControl setNeedsLayout];
[self addSubview:pageControl];