小代碼

1.增加一個旋轉動畫

UIImage *loadImage = [UIImagep_w_picpathNamed:@"detailLoad.png"];

UIImageView *loadImageView = [[[UIImageViewalloc]initWithImage:loadImage ]autorelease];

loadImageView.backgroundColor = [UIColorclearColor];

loadImageView.center =self.view.center;

loadImageView.tag =kLoadImageView;

//p_w_picpathview旋轉動畫

CAKeyframeAnimation *theAnimation = [CAKeyframeAnimationanimation];

theAnimation.values = [NSArrayarrayWithObjects:

[NSValuevalueWithCATransform3D:CATransform3DMakeRotation(0,0,0,1)],

[NSValuevalueWithCATransform3D:CATransform3DMakeRotation(3.13,0,0,1)],

[NSValuevalueWithCATransform3D:CATransform3DMakeRotation(6.26,0,0,1)],

nil];

theAnimation.cumulative =YES;

theAnimation.removedOnCompletion =YES;

theAnimation.repeatCount =HUGE_VALF;

[theAnimation setSpeed:.15];

[loadImageView.layeraddAnimation:theAnimationforKey:@"transform"];


[self.viewaddSubview:loadImageView];


2.圖片自動放大縮小

UIImage *infoImage = [UIImagep_w_picpathNamed:@"detail_info_btn.png"];

UIButton *infoButton = [[UIButtonalloc] initWithFrame:CGRectMake(0,0, infoImage.size.width, infoImage.size.height)];

[infoButton setTag:kInfoButtonTag];

[infoButtonsetImage:infoImageforState:UIControlStateNormal];

[infoButtonaddTarget:selfaction:@selector(infoButtonClicked)forControlEvents:UIControlEventTouchUpInside];

[selfaddSubview:infoButton];

[infoButton release];


//變大縮小動畫

CAKeyframeAnimation* bob = [CAKeyframeAnimationanimationWithKeyPath:@"transform"];

CATransform3D r[3] = {CATransform3DMakeScale(1.0,1.0,1),

CATransform3DMakeScale(1.2,1.2,1)};

bob.values = [NSArrayarrayWithObjects:[NSValuevalueWithCATransform3D:r[0]],

[NSValuevalueWithCATransform3D:r[1]],[NSValuevalueWithCATransform3D:r[0]],nil];

bob.repeatCount =HUGE_VAL;

bob.duration =1.75;

bob.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];

[infoButton.layer addAnimation:bobforKey:nil];

3.截取當前屏幕作爲 一張圖

//開始截圖

UIGraphicsBeginImageContext(self.view.bounds.size);

[self.view.layerrenderInContext:UIGraphicsGetCurrentContext()];

UIImage *img =UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

4.讓view 以任意方式 push出來


- (void)contentViewAniamted:(NSString *)subtype :(UIView *)currentView{

CATransition *animation = [CATransitionanimation];

animation.duration =.3;

animation.timingFunction =UIViewAnimationCurveEaseInOut;

animation.fillMode = kCAFillModeForwards;//必須設定不然不生效

animation.type = kCATransitionPush;

animation.subtype = subtype;

[currentView.layer addAnimation:animationforKey:@"animation"];

[self.viewaddSubview:currentView];

}


- (void)show

{

LeftView *currentLeft = [[[LeftViewalloc]initWithFrame:CGRectMake(0,0,600,566) ]autorelease];

currentLeft.center =self.view.center;

[selfcontentViewAniamted:kCATransitionFromTop :currentLeft];

// [self makeZSViewControllerInVisible:currentLeft];

[self.view addSubview:currentLeft];

}


5.圖片以中心點 放大

//執行動畫

[UIView beginAnimations:@""context:@""];

[UIView setAnimationDuration:1.0f];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

self.bigImageView.frame =CGRectMake(self.bigImageView.frame.origin.x - bigImage.size.width/2 ,self.bigImageView.frame.origin.y - bigImage.size.height/2, bigImage.size.width, bigImage.size.height);

[UIViewcommitAnimations];


6.讓兩個viewController以動畫形式翻出

CATransition *transition = [CATransitionanimation];

transition.duration =1;

transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

transition.type =kCATransitionPush;

transition.subtype =kCATransitionFromLeft;

transition.delegate =self;

[self.navigationController.view.layeraddAnimation:transitionforKey:nil];


[self.navigationControllerpopViewControllerAnimated:NO];


7.當鍵盤出現時 控制view的移動

//通過鍵盤出現或者消失來控制view上移


//通過鍵盤出現或者消失來控制view上移

NSNotificationCenter *center = [NSNotificationCenterdefaultCenter];

[center addObserver:selfselector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotificationobject:nil];

[center addObserver:selfselector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotificationobject:nil];


-(void)keyboardWillShow:(NSNotification *)note

{

if (self.contentView.frame.origin.y <0)return;


[UIViewanimateWithDuration:.4

animations:^(void) {

self.contentView.center =CGPointMake(self.contentView.center.x,self.contentView.center.y -300);

}];



}


-(void)keyboardWillHide:(NSNotification *)note

{

if (self.contentView.frame.origin.y ==0)return;


[UIViewanimateWithDuration:.4

animations:^(void) {

self.contentView.center =CGPointMake(self.contentView.center.x,self.contentView.center.y +300);

}];


}


8.把字符串 存儲到一個文件裏

NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,

NSUserDomainMask,

YES);

NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] :nil;

NSString *contentJsonPath = [basePathstringByAppendingPathComponent:@"content_.json"];

NSString *thumsPath = [basePath stringByAppendingPathComponent:@"thumbs.png"];

NSString *imgPath = [basePathstringByAppendingPathComponent:@"img.png"];


//json文件保存起來

NSAutoreleasePool *pool = [[NSAutoreleasePoolalloc] init];

[contentJsonwriteToFile:contentJsonPath atomically:YESencoding:NSUTF8StringEncodingerror:NULL];

[thumbs writeToFile:thumsPath atomically:YES];

[img writeToFile:imgPath atomically:YES];

[pool drain];


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章