显示标签为“iOS Development”的博文。显示所有博文
显示标签为“iOS Development”的博文。显示所有博文

2013年4月23日星期二

iOS Animation 001

Animation is Easy, today We learning basic Animation use  UIImageView(just like play film).
First need prepare a set of image frames, you can use PhotoShop or any other image edit tool do this.

Second Open Xcode , setup a project from "Single view Application" template.

Three some type 

2013年1月15日星期二

UIView Animation with block


UIViewAnimationWithBlocks us block,animation finished no longer needed write callback method,it's more  beautiful than old style.

- (void)setSelectedVeg:(id)sender
{    
    [selectedVegetableIcon setAlpha:0.0];
    
    [UIView animateWithDuration:0.4
                     animations: ^{
                         float angle = [self spinnerAngleForVegetable:sender];
                         [vegetableSpinner setTransform:CGAffineTransformMakeRotation(angle)];
                     } 
                     completion:^(BOOL finished) {
                         [selectedVegetableIcon setAlpha:1.0];
                     }];

}

code came from WWDC2010 iPlant PlantCareViem.m

old UIViewAnimation style Animation
- (void)setSelectedVeg:(id)sender
{    
    [selectedVegetableIcon setAlpha:0.0];
[UIView beginAnimations:@"setSelectedVeg" context:nil];
float angle = [self spinnerAngleForVegetable:sender];
[vegetableSpinner setTransform:CGAffineTransformMakeRotation(angle)];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(done)];
[UIView commitAnimations];
}
-(void)done
{
[selectedVegetableIcon setAlpha:1.0];
}

this article was written by me in 2010 on my Chinese blog.

[Tips] Show Circle in iOS app






first get baby icon,and add a circle crop,after that ,Superposition it with background image 
Iike this:


code 
double radians (double degrees) {return degrees * M_PI/180;}
-(UIImage*)createIconWithImage:(UIImage*)src
{
    UIImage *circle=[UIImage imageNamed:@"Face@2x.png"];
    CGFloat width=circle.size.width;
    CGFloat height=circle.size.height;
   
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedFirst);
    
    CGContextDrawImage(context, CGRectMake(0, 0, width, height), circle.CGImage);
    
    if (src.imageOrientation == UIImageOrientationLeft) {
        CGContextRotateCTM (context, radians(90));
        CGContextTranslateCTM (context, 0, -height);
        
    } else if (src.imageOrientation == UIImageOrientationRight||src.imageOrientation == UIImageOrientationRightMirrored) {
        CGContextRotateCTM (context, radians(-90));
        CGContextTranslateCTM (context, -width, 0);
        
    } else if (src.imageOrientation == UIImageOrientationUp) {
        // NOTHING
    } else if (src.imageOrientation == UIImageOrientationDown) {
        CGContextTranslateCTM (context, width, height);
        CGContextRotateCTM (context, radians(-180.));
    }
    CGContextBeginPath(context);
    
    CGContextTranslateCTM (context, 4, 4);
    CGRect rect = CGRectMake(0, 0, width-12, height-12);
    CGContextAddEllipseInRect(context, rect);
    CGContextClosePath(context);
    CGContextClip(context);
    CGContextDrawImage(context, rect , src.CGImage);
    
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSpace);
UIImage *image = [UIImage imageWithCGImage:imageMasked];
CGImageRelease(imageMasked);
    return image;
}
I thank there has a good way do this work, I use code do this like first picture in this article.

sample code : 


#import <QuartzCore/QuartzCore.h>        
self.contentView.layer.cornerRadius = 35.0;
        self.contentView.layer.borderWidth = 1.0f;
        self.contentView.layer.borderColor = [UIColor blueColor].CGColor;
        self.contentView.layer.shadowColor = [UIColor blueColor].CGColor;
        self.contentView.layer.shadowOffset = CGSizeMake(2.0, 2.0);
        self.contentView.layer.shadowOpacity= 0.5;
        self.contentView.backgroundColor = [UIColor underPageBackgroundColor];


reference 
Apple CALayer Class Reference