2
在我的應用程序中使用UIControlpage。加載圖像併成功顯示在頁面控制中。但我想顯示圖像動畫像從右到左移動。使用定時器調用頁面控制並增加陣列數量。UIpagecontrol需要動畫Rigth到左邊
////使用NSTimer調用函數來顯示動畫。
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(loadNextController)
userInfo:nil
repeats:YES];
ScrollViewPage = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, frameX, frameY)];
ScrollViewPage.pagingEnabled = YES;
ScrollViewPage.backgroundColor=[UIColor redColor];
ScrollViewPage.delegate = self;
ScrollViewPage.backgroundColor = [UIColor clearColor];
ScrollViewPage.contentSize = CGSizeMake(frameX, frameY);
ScrollViewPage.showsHorizontalScrollIndicator = NO;
ScrollViewPage.pagingEnabled = YES;
pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(100,self.view.frame.size.height-100,self.view.frame.size.width-200,100);
pageControl.numberOfPages = [_pageImages count];
pageControl.currentPage = 0;
[self.view addSubview: ScrollViewPage];
for(int i = 0; i < [_pageImages count]; i++)
{
NSURL *url = [NSURL URLWithString:[_pageImages objectAtIndex:i]];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *tmpImage = [UIImage imageWithData:data];
_backgroundImageView = [[UIImageView alloc] initWithImage:tmpImage];
_backgroundImageView.frame = CGRectMake(frameX * i, 0.0, frameX, frameY);
[ScrollViewPage addSubview:_backgroundImageView];
}
ScrollViewPage.contentSize = CGSizeMake(frameX*[_pageImages count], frameY);
pageControl.backgroundColor=[UIColor orangeColor];
[self.view addSubview:pageControl];
[pageControl addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventValueChanged];
/////這裏所說的定時器功能
- (void)loadNextController
{
pageControl.currentPage = (pageControl.currentPage+1)%self.pageImages.count;
ScrollViewPage.contentOffset = CGPointMake(pageControl.currentPage * self.view.bounds.size.width, 0);
}
在這裏,我需要顯示留給了uipagecontrol正確的舉措。幫助我..
非常感謝你..爲我工作.. –
一個疑問..顯示[_ImageImages數組]中的所有圖像後,如何移動uipagecontrol中的第一個圖像沒有動畫。這意味着所有圖像都會返回並轉到第一張圖像。我需要它自動來到第一個圖像。幫助我... –
我爲此添加了這個概念。我希望你能理解它。 –