`
yidongkaifa
  • 浏览: 4064299 次
文章分类
社区版块
存档分类
最新评论

UIView效果

 
阅读更多

[UIViewbeginAnimations:nilcontext:nil];

[UIView setAnimationCurve:UIViewAnimationCurveLinear];

[UIView setAnimationDelegate:self];

[UIView setAnimationDuration:2];

[self.viewsetAlpha:0.0];

[UIViewcommitAnimations];

[UIViewbeginAnimations:nilcontext:nil];

[UIView setAnimationCurve:UIViewAnimationCurveLinear];

[UIView setAnimationDelegate:self];

[UIView setAnimationDuration:0.5];

[self.viewsetAlpha:1.0];

// [loginViewController.view setFrame:CGRectMake(0, 20, 320, 480)];

// TODO:中间可以修改很多东西,在这个view范围内

// 比如改变 scrollview 大小

//scrollView.contentInset=UIEdgeInsetsMake(60.0f,0.0f,0.0f,0.0f);

// [self addChildViewController:loginViewController];

[UIViewcommitAnimations];



如:

[UIViewbeginAnimations:nilcontext:NULL];

[UIViewsetAnimationDuration:.3];

[scrollViewsetContentInset:UIEdgeInsetsMake(0.0f,0.0f,0.0f,0.0f)];

[UIViewcommitAnimations];



CALayer 旋转效果:

CALayer*layer = [CALayerlayer];

layer.frame=CGRectMake(25.0f, frame.size.height-65.0f,30.0f,55.0f);

layer.contentsGravity=kCAGravityResizeAspect;

layer.contents= (id)[UIImageimageNamed:@"blueArrow.png"].CGImage;


[[selflayer]addSublayer:layer];


[CATransactionbegin];

[CATransactionsetAnimationDuration:FLIP_ANIMATION_DURATION];

layer.transform=CATransform3DMakeRotation((M_PI/180.0) *180.0f,0.0f,0.0f,1.0f);


[CATransactioncommit];


把layer 加入到 UIView 里面,实现层的旋转动画效果。

设置uiView,成圆角矩形


今天要做一个button, 使用系统的没啥意思,感觉学不到新东西,所以自己做uiview,(以前做symbian做神经了,啥都喜欢自己做)自己做委托,自己做控件,大家别说我贱哦。

画个圆角的矩形没啥难的,有两种方法:

1 。直接修改view的样式,系统提供好的了:

view.layer.cornerRadius = 6;
view.layer.masksToBounds = YES;

用layer做就可以了,十分简单。这个需要倒库QuartzCore.framework;


2. 在view 里面画圆角矩形

CGFloat radius = 20.0;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1);
CGFloat minx = CGRectGetMinX(rect), midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect);
CGFloat miny = CGRectGetMinY(rect), midy = CGRectGetMidY(rect), maxy = CGRectGetMaxY(rect);
CGContextMoveToPoint(context, minx, midy);
CGContextAddArcToPoint(context, minx, miny, midx, miny, radius);
CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius);
CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFill);


用画笔的方法,在drawRect里面做。

希望大家都不要满足现状,老用xib, 多思考,这样才不至于被淘汰。

UIView 进行各种动画展示及其用法解释

//第一种动画方式

- (void) first_animations

{
[UIViewbeginAnimations:nilcontext:nil]; //启动动画动作
[UIViewsetAnimationRepeatCount:1];//设置是否重复播放
[UIViewsetAnimationDuration:1];//设置动画持续时间
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];//动画曲线,具体的应用 ,可以经过实验检测
[UIViewsetAnimationDelegate:self];//动画块的某个方法(最下方),委托到本类的实例
[UIViewsetAnimationDidStopSelector:@selector(resetView)];//动画结束后去执行的方法

CGAffineTransformoneTransform =CGAffineTransformRotate(self.animatView.transform, degreesToRadian(180));//进行 CGAffineTransform 方式的动作(旋转拉伸等等)===>(对于CGAffineTransform 可以另外开辟一个关于CGAffineTransform使用详情的文章进行专门介绍)

CGAffineTransformtwoTransform =CGAffineTransformTranslate(self.animatView.transform,0,-100);
CGAffineTransformnewTransform =CGAffineTransformConcat(oneTransform, twoTransform);
[self.animatViewsetTransform:newTransform];
[UIViewcommitAnimations];//有些网友说,这是动画结束.起始经过本人尝试试验.其实应该是,执行上方定义的动画块内容.
}

//第二中动画定义方式
- (void) second_animations
{
CABasicAnimation*animation = [CABasicAnimationanimationWithKeyPath:@"opacity"];
[animationsetDuration:1];
[animationsetRepeatCount:0];
[animationsetAutoreverses:YES];//自动反向动画
[animationsetFromValue:[NSNumbernumberWithFloat:1.0]];
[animationsetToValue:[NSNumbernumberWithFloat:0]];
[animationsetDelegate:self];
[self.animatView.layeraddAnimation:animationforKey:@"firstView-Opacity"];
}
- (void) third_animations
{
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationRepeatCount:1];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];
[UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromRightforView:self.containViewcache:YES];
[UIViewsetAnimationDidStopSelector:@selector(animationDidStop:finished:)];
[UIViewcommitAnimations];
}
- (void) fourth_animations
{
CATransition*transition = [CATransitionanimation];
transition.duration = 1.0f; /* 间隔时间*/
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut]; /* 动画的开始与结束的快慢*/
transition.type = @"pageCurl"; //@"cube" @"moveIn" @"reveal" @"fade"(default) @"pageCurl" @"pageUnCurl" @"suckEffect" @"rippleEffect" @"oglFlip"
transition.subtype =kCATransitionFromRight;
transition.removedOnCompletion =YES;
transition.fillMode =kCAFillModeBackwards;
transition.delegate = self;
[self.animatView.layeraddAnimation:transitionforKey:nil];
}
-(void) resetView
{
[self.animatViewsetTransform:CGAffineTransformRotate(self.animatView.transform, degreesToRadian(180))];
self.animatView.frame = CGRectMake(0, 0, 280, 200);
}
#pragma mark Delegate Methods
- (void)animationDidStop:(CAAnimation *) theAnimation finished:(BOOL) flag {
self.animatView.frame = CGRectMake(0, 0, 280, 200);
}

#define degreesToRadian(x) (M_PI * (x) / 180.0)

================再次挖井的分割线07.11=============




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics