UIView 基礎動畫


//
//  CHAppDelegate.m
//  uiAn動畫
//
//  Created by imac on 14-10-14.
//  Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
//

#import "CHAppDelegate.h"

@implementation CHAppDelegate
{
    UIImageView * _imageView;
}
- (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];
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 30, 30)];
    imageView.center = CGPointMake(320-15,100);
    NSMutableArray * images = [[NSMutableArray alloc]init];
    for (int i = 1; i < 9; i++) {
        NSString * path =[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"%.2d",i] ofType:@"JPG"];
        UIImage * image = [UIImage imageWithContentsOfFile:path];
        [images addObject:image];
    }
    
    imageView.animationImages = images;
    
//    
//    imageView.animationDuration = 0.5;
//    
//   imageView.animationRepeatCount = 0;
//
    _imageView = imageView;
    
    
    [images release];
    [self useAnimate];
    NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(useAnimate) userInfo:nil repeats:YES];
    [self.window addSubview:imageView];
    [imageView release];
    
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)useAnimate
{
    
    //_imageView.animationRepeatCount = 4;
    
    [UIView animateWithDuration:2  animations:^{
        
        CGPoint point = _imageView.center;
        point.x -= 320-30;
        _imageView.center = point;
//        if (_imageView.center.x > 0) {
//            _imageView.transform =(CGAffineTransformTranslate(_imageView.transform, -300, 0));
//        }
        
    }completion:^(BOOL finished) {
        
        _imageView.transform = CGAffineTransformScale(_imageView.transform, -1, 1);
        [UIView animateWithDuration:2 animations:^{
            CGPoint point = _imageView.center;
            point.x += 320-30;
            _imageView.center = point;
        }completion:^(BOOL finished) {
            _imageView.transform = CGAffineTransformScale(_imageView.transform, -1, 1);
        }];
        
    }];
    
    [_imageView startAnimating];

    
    
}

- (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


發佈了68 篇原創文章 · 獲贊 10 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章