iOS开发基础知识--碎片38

摘要:
iOS开发基础知识--碎片38iOS开发基础知识--碎片38iOS开发基础知识--碎片381:FCUUID获取设备标识的运用a:作者githun地址https://github.com/fabiocaccamo/FCUUID因为里面还用到作者的另外一个类UICKeyChainStore地址:https://github.com/kishikawakatsumi/UICKeyChainStoreb:
iOS开发基础知识--碎片38

iOS开发基础知识--碎片38

iOS开发基础知识--碎片38

1:FCUUID获取设备标识的运用

a:作者 githun地址 https://github.com/fabiocaccamo/FCUUID

因为里面还用到作者的另外一个类UICKeyChainStore地址:https://github.com/kishikawakatsumi/UICKeyChainStore

b:在项目中添加 Security.framework

c:导入头文件#import “FCUUID.h"

复制代码
// 每次运行应用都会变
+(NSString *)uuid;
//changes each time (no persistent), but allows to keep in memory more temporary uuids
+(NSString *)uuidForKey:(id<NSCopying>)key;
// 每次运行应用都会变
+(NSString *)uuidForSession;
// 重新安装的时候会变
+(NSString *)uuidForInstallation;
// 卸载后重装会变
+(NSString *)uuidForVendor;
// 抹掉iPhone的时候才会变,适合做唯一标识
+(NSString *)uuidForDevice;
复制代码

iOS开发基础知识--碎片38第3张

2:在图片增加一个外围的白色边框

复制代码
-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {
    //UIGraphicsBeginImageContext(image.size);
    //解决失真 模糊的问题
    UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]);
    CGContextRef context =UIGraphicsGetCurrentContext();
    //圆的边框宽度为2,颜色为红色
    CGContextSetLineWidth(context,2);
    CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
    CGRect rect = CGRectMake(inset, inset, image.size.width - inset *2.0f, image.size.height - inset *2.0f);
    CGContextAddEllipseInRect(context, rect);
    CGContextClip(context);
    //在圆区域内画出image原图
    [image drawInRect:rect];
    CGContextAddEllipseInRect(context, rect);
    CGContextStrokePath(context);
    //生成新的image
    UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newimg;
}
复制代码

注意:如果使用UIGraphicsBeginImageContext(image.size);会导致图片有点失真模糊,可以采用UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]);还有如果在视图上进行画圆,只有在视图没有其它盖住时才看得到,比如如果有个背景图片,那么它就没盖住了;

3:在普通视图控制器包一个UINavigation

复制代码
#pragma mark 添加导航栏
-(void)addNavigationBar{
    //创建一个导航栏
    UINavigationBar *navigationBar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44+20)];
    //navigationBar.tintColor=[UIColor whiteColor];
    [self.view addSubview:navigationBar];
    //创建导航控件内容
    UINavigationItem *navigationItem=[[UINavigationItem alloc]initWithTitle:@"Web Chat"];
    //左侧添加登录按钮
    UIBarButtonItem *loginButton=[[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStyleDone target:self action:@selector(login)];
    navigationItem.leftBarButtonItem=loginButton;
    //添加内容到导航栏
    [navigationBar pushNavigationItem:navigationItem animated:NO];
}
复制代码

4:系统自带定位坐标转为城市名

复制代码
    //系统自带定位
    [[MPLocationManager shareInstance] startSystemLocationWithRes:^(CLLocation *loction, NSError *error) {
        if (!error) {
            CLGeocoder *geocoder=[[CLGeocoder alloc]init];
            [geocoder reverseGeocodeLocation:loction completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
                if (placemarks.count>0) {
                    CLPlacemark *placemark=[placemarks objectAtIndex:0];
                    //获取城市
                    NSString *city = placemark.locality;
                    if (!city) {
                        //四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)
                        city = placemark.administrativeArea;
                    }
                    //有差异才改变
                    if(![BBUserDefault.LocationCity isEqualToString:city])
                    {
                        BBUserDefault.LocationCity=city;
                    }
                    NSLog(@"当前城市:[%@]",city);
                }
            }];
        }
        BBUserDefault.latiude=[NSString stringWithFormat:@"%f",loction.coordinate.latitude];
        BBUserDefault.longitude=[NSString stringWithFormat:@"%f",loction.coordinate.longitude];
        NSLog(@"定位信息:[%f,%f]",loction.coordinate.latitude,loction.coordinate.longitude);
    }];
复制代码

注意:MPLocationManager.h类的代码如下:

复制代码
#import <Foundation/Foundation.h>
typedef void(^KSystemLocationBlock)(CLLocation *loction, NSError *error);
@interface MPLocationManager : NSObject
+ (id)shareInstance;
/**
 *  启动系统定位
 *
 *  @param systemLocationBlock 系统定位成功或失败回调成功
 */
- (void)startSystemLocationWithRes:(KSystemLocationBlock)systemLocationBlock;
@end
复制代码
复制代码
//
//  MPLocationManager.m
//  MobileProject
//
//  Created by wujunyang on 16/1/15.
//  Copyright © 2016年 wujunyang. All rights reserved.
//
#import "MPLocationManager.h"
@interface MPLocationManager()<CLLocationManagerDelegate>
@property (nonatomic, readwrite, strong) CLLocationManager *locationManager;
@property (nonatomic, readwrite, copy) KSystemLocationBlock kSystemLocationBlock;
@end
@implementation MPLocationManager
+ (id)shareInstance{
    static id helper = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        helper = [[MPLocationManager alloc]  init];
    });
    return helper;
}
#pragma mark - 苹果
/**
 *  苹果系统自带地图定位
 */
- (void)startSystemLocationWithRes:(KSystemLocationBlock)systemLocationBlock{
    self.kSystemLocationBlock = systemLocationBlock;
    if(!self.locationManager){
        self.locationManager =[[CLLocationManager alloc] init];
        self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
        //        self.locationManager.distanceFilter=10;
        if ([UIDevice currentDevice].systemVersion.floatValue >=8) {
            [self.locationManager requestWhenInUseAuthorization];//使用程序其间允许访问位置数据(iOS8定位需要)
        }
    }
    self.locationManager.delegate=self;
    [self.locationManager startUpdatingLocation];//开启定位
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    CLLocation *currLocation=[locations lastObject];
    self.locationManager.delegate = nil;
    [self.locationManager stopUpdatingLocation];
    self.kSystemLocationBlock(currLocation, nil);
}
/**
 *定位失败,回调此方法
 */
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    if ([error code]==kCLErrorDenied) {
        NSLog(@"访问被拒绝");
    }
    if ([error code]==kCLErrorLocationUnknown) {
        NSLog(@"无法获取位置信息");
    }
    self.locationManager.delegate = nil;
    [self.locationManager stopUpdatingLocation];
    self.kSystemLocationBlock(nil, error);
}
@end
复制代码

5:初始化init传参的一些样例

复制代码
@implementation ZOCEvent
- (instancetype)initWithTitle:(NSString *)title
                         date:(NSDate *)date
                     location:(CLLocation *)location
{
    self = [super init];
    if (self) {
        _title    = title;
        _date     = date;
        _location = location;
    }
    return self;
}
- (instancetype)initWithTitle:(NSString *)title
                         date:(NSDate *)date
{
    return [self initWithTitle:title date:date location:nil];
}
- (instancetype)initWithTitle:(NSString *)title
{
    return [self initWithTitle:title date:[NSDate date] location:nil];
}
@end
复制代码

6:embedded dylibs/frameworks are only

supported on iOS 8.0 and later 错误解决

ld: warning: embedded dylibs/frameworks only run on iOS 8 or later
ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later (@rpath/XXX.framework/XXX) for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

原因:主要是因为XXX的framework支持的最低开发环境为8.0,而使用该framework的工程支持版本为8.0以下(我这里的环境为4.3)
解决方法:选择低版本的开发环境,重新编译XXX的framework

iOS开发基础知识--碎片38第16张

7:图片左右上下拉伸不变形stretchableImageWithLeftCapWidth

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:

(NSInteger)topCapHeight 这个函数是UIImage的一个实例函数,它的功能是创建一个内容可拉伸,而边角不拉伸的图片,需要两个参数,第一个是左边不拉伸区域的宽度,第二个参数是上面不拉伸的高度。

根据设置的宽度和高度,将接下来的一个像素进行左右扩展和上下拉伸。

注意:可拉伸的范围都是距离leftCapWidth后的1竖排像素,和距离topCapHeight后的1横排像素。

参数的意义是,如果参数指定10,5。那么,图片左边10个像素,上边5个像素。不会被拉伸,x坐标为11和一个像素会被横向复制,y坐标为6的一个像素会被纵向复制。

注意:只是对一个像素进行复制到一定宽度。而图像后面的剩余像素也不会被拉伸。

    UIImage *img=[UIImage imageNamed:@"bubbleSelf.png"];
    img=[img stretchableImageWithLeftCapWidth:15 topCapHeight:12];
    UIImageView *imgView=[[UIImageView alloc]initWithImage:img];
    [imgView setFrame:CGRectMake(10, 10, 200, 200)];
    [self. view addSubview:imgView];

iOS开发基础知识--碎片38第17张

免责声明:文章转载自《iOS开发基础知识--碎片38》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Jexus 负载均衡SVG动画下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Oracle函数应用与查询聚合统计

Oracle预定义函数 Oracle数据库系统中定义了很多的函数(预定义)。这些函数能够完成本身特有的数据操作功能,执行效率更高并重复使用。 Oracle中的预定义函数按照对数据的操作执行特征可以分为: 单行函数——对每个记录执行一次 聚合函数(多行函数)——对多个记录行执行一次 单行函数 字符串函数 日期时间函数 数学计算函数 其它特殊函数 字符串操作函...

ios 清理缓存

//拿到要清理的路径,其实就是caches的路径,一般像这种很多地方都会用到的地方真好搞成宏,不过现在苹果不提倡用宏了 //在swift中可以定义成全局的常量 //遍历caches,将内部的文件大小计算出来,点击确认删除的话直接删除全部文件,如果有不想清理的文件,可以在遍历文件时根据路径过滤掉 {...

Oracle- 存储过程和异常捕捉

这段时间晚上有时候去打打球,回家看看电视剧,日子一天天过……。学了点ORACLE存储过程基础,作一下备注,以便日后需查阅。 创建无参存储过程 create procedure p_myPro1 is begin insert into dept(deptno,dname,loc) values(60,'ccx','321321'); end; 修改无参...

java把一段时间分成周,月,季度,年的时间段

package com.mq.test.activeMQ; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date;...

iOS 拼接字符串

NSString  *str1=@"我爱"; NSString *str2=@"祖国"; (1)  NSString *all= [NSString stringWithFormat:@"%@>%@",str1,str2];    (2)  NSString *all2= [type stringByAppendingString:subtype];...

【Python之路】特别篇--ECMA对象、DOM对象、BOM对象

ECMA对象从传统意义上来说,ECMAScript 并不真正具有类。事实上,除了说明不存在类,在 ECMA-262 中根本没有出现“类”这个词。 ECMAScript 定义了“对象定义”,逻辑上等价于其他程序设计语言中的类。 var o = new Object(); 对象的概念与分类: 由ECMAScript定义的本地对象.独立于宿主环境的 ECMAS...