ios UI控件的简单整理(2)

#pragma mark - 图片截取- (UIImage*)clipImage:(UIImage*)image inRect:(CGRect)rect

{//返回image中rect范围内的图片CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, rect);UIImage*subImage = [UIImageimageWithCGImage:imageRef];returnsubImage;

}#pragma mark - 计算字符串尺寸// 计算一个字符串完整展示所需要的size// 第一个参数是最大不能超过的size// 第二个参数固定写法// 第三个参数是计算size时字符串的属性CGSizesize = [str boundingRectWithSize:CGSizeMake(width -5, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionarydictionaryWithObjectsAndKeys:self.label.font, NSFontAttributeName,nil] context:nil].size;// 根据计算的结果修改label的frameCGRectframe =self.label.frame;

frame.size.width= size.width+5;

frame.size.height= size.height+5;self.label.frame= frame;

#pragma mark - 动画#pragma mark -简单动画/** 动画1 **/// 简单动画,可以修改frame,alpha(透明度1.0),背景色// 完成frame修改的动作需要两秒,但是代码不会卡住,代码会继续运行[UIViewanimateWithDuration:2animations:^{

bigView.frame= frame;

}];/** 动画2 **/[UIViewanimateWithDuration:2animations:^{

bigView.frame= frame;

} completion:^(BOOLfinished) {NSLog(@"动画完成以后的回调=%d",finished);

}];/** 动画3 **/// 开始简单动画[UIViewbeginAnimations:nilcontext:NULL];// 设置动画时间[UIViewsetAnimationDuration:2];//... 添加代码,属于要展示动画的区域// 提交动画[UIViewcommitAnimations];/** 跟随模式 **//*

UIViewAutoresizingNone                = 0,

UIViewAutoresizingFlexibleLeftMargin  = 1 << 0,

UIViewAutoresizingFlexibleWidth        = 1 << 1,

UIViewAutoresizingFlexibleRightMargin  = 1 << 2,

UIViewAutoresizingFlexibleTopMargin    = 1 << 3,

UIViewAutoresizingFlexibleHeight      = 1 << 4,

UIViewAutoresizingFlexibleBottomMargin = 1 << 5

*/// 允许子视图跟随bigView.autoresizesSubviews=YES;// 子视图跟随的模式smallView.autoresizingMask= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;#pragma mark -基础动画/***************CABasicAnimation************/// 创建核心动画// 缩放比例用transform.scale//transform.scale代表缩放(倍数)//transform.rotation.x  transform.rotation.y  transform.rotation.z 代表旋转(角度)CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];// 动画的始末值// @0.5 相当于 [NSNumber numberWithFloat:0.5]ani.fromValue= @0;

ani.toValue= @M_PI;// 单次动画时间ani.duration=2;// 重复次数ani.repeatCount=10;// 动画返回形式ani.autoreverses=YES;// 添加动画[view.layeraddAnimation:ani forKey:@"aaa"];// 移除动画[longPressGR.view.layerremoveAnimationForKey:@"aaa"];#pragma mark -转场动画// 创建转场动画CATransition *tt = [CATransition animation];// 动画时间tt.duration=2;// 方向tt.subtype= kCATransitionFromBottom;//四种预设,某些类型中此设置无效kCATransitionFromRight

kCATransitionFromLeft

kCATransitionFromTop

kCATransitionFromBottom// 类型(系统自带的有4个)tt.type= kCATransitionMoveIn;

tt.type= @"rotate";/*

1---->

#define定义的常量(基本型)

kCATransitionFade  交叉淡化过渡

kCATransitionMoveIn 新视图移到旧视图上面

kCATransitionPush  新视图把旧视图推出去

kCATransitionReveal 将旧视图移开,显示下面的新视图

2--->

苹果官方自定义类型:

fade moveIn push reveal        和上面的四种一样

pageCurl pageUnCurl            翻页

rippleEffect                    滴水效果

suckEffect                      收缩效果,如一块布被抽走

cube alignedCube                立方体效果

flip alignedFlip oglFlip        翻转效果

rotate                          旋转

cameraIris cameraIrisHollowOpen cameraIrisHollowClose 相机

*/[self.navigationController.view.layeraddAnimation:tt forKey:nil];

[self.navigationControllerpushViewController:dvc animated:NO];#pragma mark - UIApplicationopenURL:

●UIApplication有个功能⼗十分强⼤大的openURL:⽅方法 - (BOOL)openURL:(NSURL*)url;

● openURL:⽅方法的部分功能有

➢ 打电话UIApplication*app = [UIApplicationsharedApplication]; [app openURL:[NSURLURLWithString:@"tel://10086"]];

➢ 发短信

[app openURL:[NSURLURLWithString:@"sms://10086"]];

➢ 发邮件

[app openURL:[NSURLURLWithString:@"mailto://[email protected]"]];

➢ 打开⼀一个⺴⽹网⻚页资源

[app openURL:[NSURLURLWithString:@"http://ios.itcast.cn"]];

你可能感兴趣的:(ios UI控件的简单整理(2))