切换动态图

来源:互联网 发布:数据的保密性 编辑:程序博客网 时间:2024/04/26 11:48
////  AppDelegate.h//  804 作业 切换动态图////  Created by dllo on 15/8/4.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end
<pre name="code" class="objc">////  AppDelegate.m//  804 作业 切换动态图////  Created by dllo on 15/8/4.//  Copyright (c) 2015年 flg. All rights reserved.//#import "AppDelegate.h"#import "MainViewController.h"@interface AppDelegate ()@end@implementation AppDelegate-(void)dealloc{    [_window release];    [super dealloc];}- (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];    [self.window makeKeyAndVisible];    [_window release];    MainViewController *mainVC=[[MainViewController alloc] init];    self.window.rootViewController=mainVC;    [mainVC release];    return YES;}- (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


<pre name="code" class="objc">////  MainViewController.h//  804 作业 切换动态图////  Created by dllo on 15/8/4.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface MainViewController : UIViewController@end


<pre name="code" class="objc">////  MainViewController.m//  804 作业 切换动态图////  Created by dllo on 15/8/4.//  Copyright (c) 2015年 flg. All rights reserved.//#import "MainViewController.h"@interface MainViewController ()@property(nonatomic,retain)UIImageView *imageView1;@property(nonatomic,retain)UIImageView *imageView2;@property(nonatomic,retain)UIImageView *imageView3;@property(nonatomic,retain)NSMutableArray *arry1;@property(nonatomic,retain)NSMutableArray *arry2;@property(nonatomic,retain)NSMutableArray *arry3;@property(nonatomic,retain)UISegmentedControl *seg;@end@implementation MainViewController- (void)dealloc{    [_arry1 release];    [_arry2 release];    [_arry3 release];    [_seg release];    [_imageView1 release];    [_imageView2 release];    [_imageView3 release];    [super dealloc];}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    self.imageView1=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];    [self.view addSubview:self.imageView1];    self.imageView1.backgroundColor=[UIColor orangeColor];    [self.imageView1 release];    //添加动画    self.arry1=[NSMutableArray array];    for (NSInteger i=1; i<16; i++) {        NSString *str=[NSString stringWithFormat:@"dodo_%02ld.jpg",i];        UIImage *image=[UIImage imageNamed:str];        [self.arry1 addObject:image];    }    self.imageView1.animationImages=self.arry1;    self.imageView1.animationDuration=1;    [self.imageView1 startAnimating];////////////////////////    self.imageView2=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];    [self.view addSubview:self.imageView2];    self.imageView2.backgroundColor=[UIColor redColor];    [self.imageView2 release];    //添加动画    self.arry2=[NSMutableArray array];    for (NSInteger i=1; i<12; i++) {        NSString *str=[NSString stringWithFormat:@"tutu_%02ld.jpg",i];        UIImage *image=[UIImage imageNamed:str];        [self.arry2 addObject:image];    }    self.imageView2.animationImages=self.arry2;    self.imageView2.animationDuration=2;    [self.imageView2 startAnimating];    self.imageView3=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];    [self.view addSubview:self.imageView3];    self.imageView3.backgroundColor=[UIColor yellowColor];    [self.imageView3 release];    //添加动画    self.arry3=[NSMutableArray array];    for (NSInteger i=1; i<57; i++) {        NSString *str=[NSString stringWithFormat:@"%02ld.jpg",i];        UIImage *image=[UIImage imageNamed:str];        [self.arry3 addObject:image];    }    self.imageView3.animationDuration=3;    self.imageView3.animationImages=self.arry3;    [self.imageView3 startAnimating];    self.seg=[[UISegmentedControl alloc] initWithItems:@[@"1",@"2",@"3"]];    self.seg.frame=CGRectMake(50, 400, 300, 30);    [self.view addSubview:self.seg];    self.seg.backgroundColor=[UIColor lightGrayColor];    self.seg.layer.borderColor=[UIColor orangeColor].CGColor;    [self.seg release];    [self.seg addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];}-(void)change:(UISegmentedControl *)change{    ///方法1.//    NSInteger index=self.seg.selectedSegmentIndex;    switch (self.seg.selectedSegmentIndex) {        case 0:            [self.view bringSubviewToFront:self.imageView1];            break;        case 1:             [self.view bringSubviewToFront:self.imageView2];            break;        case 2:            [self.view bringSubviewToFront:self.imageView3];            break;        default:            break;    }    ///方法2.//    if (self.seg.selectedSegmentIndex==0) {//        [self.view bringSubviewToFront:self.imageView1];//    }else if(self.seg.selectedSegmentIndex==1){//       [self.view bringSubviewToFront:self.imageView2];//    }else if(self.seg.selectedSegmentIndex==2){//       [self.view bringSubviewToFront:self.imageView3];//    }}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    // Get the new view controller using [segue destinationViewController].    // Pass the selected object to the new view controller.}*/@end



0 0
原创粉丝点击