swanzhu學ios(四)之UIScrollView與UIPageControl

來源:互聯網
上載者:User

標籤:



素材地址    http://download.csdn.net/download/swanzhu/9002215


////  ZYAppDelegate.m//  ScrollView_Page////  Created by mac on 15-8-13.//  Copyright (c) 2015年 baidu. All rights reserved.//#import "ZYAppDelegate.h"@implementation ZYAppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];                // 滑動視圖       scrollview=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 10, 320, 200)];        for (int i=0; i<3; i++) {        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(320*i, 0, 320, 200)];        NSString *imgName=[NSString stringWithFormat:@"%d.jpg",i+1];                imageView.image=[UIImage imageNamed:imgName];                [scrollview addSubview:imageView];    }            scrollview.contentSize=CGSizeMake(320*3, 200);    scrollview.pagingEnabled=YES;    [self.window addSubview:scrollview];    //    設定代理    scrollview.delegate=self;                //  pageControl    pageControl=[[UIPageControl alloc] initWithFrame:CGRectMake(100, 180, 120, 40)];    pageControl.numberOfPages=3;    [self.window addSubview:pageControl];        [pageControl addTarget:self action:@selector(changeValue) forControlEvents:UIControlEventValueChanged];        [self.window makeKeyAndVisible];                [NSTimer  scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];                            return YES;}-(void)onTimer{           static int count=320;    [scrollview setContentOffset:CGPointMake(scrollview.contentOffset.x+count, 0) animated:YES];                if (scrollview.contentOffset.x==320) {        count=-count;    }              }-(void)changeValue{//    scrollview.contentOffset.x=pageControl.currentPage*320;//    scrollview.contentOffset=CGPointMake(pageControl.currentPage*320, 0);    [scrollview setContentOffset:CGPointMake(pageControl.currentPage*320, 0) animated:YES];}//結束減速之後調用的方法-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{   pageControl.currentPage =scrollView.contentOffset.x/320;}- (void)applicationWillResignActive:(UIApplication *)application{    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application{    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application{    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application{    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application{    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

swanzhu學ios(四)之UIScrollView與UIPageControl

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.