title: UIView 相关知识
date: 2015-12-13 22:47
categories: IOS
tags: UIView
小小程序猿
我的博客:http://daycoding.com
masonry 添加约束,并修改约束添加View动画
//添加约束
masView = [UIView new];
masView.backgroundColor = [UIColor redColor];
[self.view addSubview:masView];
[masView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.view).offset(20);//距离self.view左侧20
make.top.equalTo(self.view).offset(200);//距离self.view顶部200
make.width.offset(80);//宽度80
make.height.offset(80);//高度80
}];
//更新约束并添加动画,如果更新不成功可尝试 mas_remakeConstraints
[masView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.and.height.offset(100);
make.leading.equalTo(self.view).offset(100);
}];
[UIView animateWithDuration:3 animations:^{
[self.view layoutIfNeeded];
}];
uiview 圆角设置
m_mainImgView.layer.cornerRadius = 6;
m_mainImgView.layer.masksToBounds = YES;
UIView缩放动画
-(void)mapView:(BMKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
/* 为新添的annotationView添加弹出动画. */
for (UIView *view in views)
{
[self addBounceAnnimationToView:view];
}
}
/* annotation弹出的动画. */
- (void)addBounceAnnimationToView:(UIView *)view
{
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
bounceAnimation.values = @[@(0.05), @(1.1), @(0.9), @(1)];
bounceAnimation.duration = 0.6;
NSMutableArray *timingFunctions = [[NSMutableArray alloc] initWithCapacity:bounceAnimation.values.count];
for (NSUInteger i = 0; i < bounceAnimation.values.count; i++)
{
[timingFunctions addObject:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
}
[bounceAnimation setTimingFunctions:timingFunctions.copy];
bounceAnimation.removedOnCompletion = NO;
[view.layer addAnimation:bounceAnimation forKey:@"bounce"];
}
边框阴影
- (void)viewDidLoad
{
[self.view setBackgroundColor:[UIColor whiteColor]];
UIView *shadowView=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 120, 120)];
[shadowView setBackgroundColor:[UIColor grayColor]];
[shadowView.layer setCornerRadius:4.0f];//设置View圆角
[shadowView.layer setShadowColor:[UIColor blackColor].CGColor];//设置View的阴影颜色
[shadowView.layer setShadowOpacity:0.8f];//设置阴影的透明度
[shadowView.layer setOpacity:0.5f];//设置View的透明度
[shadowView.layer setShadowOffset:CGSizeMake(4.0, 3.0)];//设置View Shadow的偏移量
[self.view addSubview:shadowView];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
552

被折叠的 条评论
为什么被折叠?



