iOS开发之笔记摘录

LaunchImage Icon尺寸 与 CocoaPods 与

2017-07-13  本文已影响80784人  平安喜乐698
目录

  1. LaunchImage Icon尺寸规范
  2. CocoaPods
  3. pch配置
  4. AppDelegate
  5. UINavigationController  UITabbarController
  6. 上线
1. LaunchImage Icon尺寸规范
1.1 LaunchImage(必须是png,且大小不能有误)
    iPhone Portrait iOS 8-Retina HD 5.5 (1242×2208) @3x
    iPhone Portrait ios 8-Retina HD 4.7 (750×1334)  @2x
    
    iPhone Portrait iOS 7,9-2x          (640×960)   @2x
    iPhone Portrait iOS 7,9-Retina 4    (640×1136)  @2x
    
    iPhone Portrait iOS 5,6-1x          (320×480)   @1x
    iPhone Portrait iOS 5,6-2x          (640×960)   @2x
    iPhone Portrait iOS 5,6-Retina4     (640×1136)  @2x
D32689AF-8E4A-46DE-94F9-F105545272F4.png FFC6AA1D-176C-4E0E-9C39-685ED07D02FD.png
1.2 Icon

图标下为 一倍


Icon
2. CocoaPods

安装

// 修改源地址(旧地址被墙)
    gem sources --remove https://rubygems.org/
    gem sources -a https://ruby.taobao.org/
            // 查看源地址 
            gem sources -l  
// 安装/更新cocoaPods
    sudo gem install cocoapods    (可加  -n  /usr/local/bin cocoapods)

提示:
  1、问题:RuntimeError - [Xcodeproj] Unknown object version 表示cocoaPods的版本和Xcode的版本不一致导致的。
     解决:更新cocoaPods

使用

0.
pod search 三方库


1.
vim Podfile

platform:ios,'8.0'
target "项目名" do
    inhibit_all_warnings!#屏蔽cocoapods库里的所有警告
    use_frameworks!
pod   'AFNetworking'
end

退出并保存   ESC   :WQ  
编辑               i


pod update
点击xcworkspace

cmd+B(每次添加新的第三方库后 引入头文件时找不到,需要先编译一下)
3. PCH

用于

1.  存放 宏定义
2.  存放 常用头文件

配置


新建pch文件.png 配置路径---可以拖拽文件直接生成路径.png
常量使用const而不是宏:
  1.宏过多会影响开发效率(宏是在预编译阶段处理的),const是在编译阶段处理的且只会被编译一次。
  2.宏只是简单的替换,不会检查错误,而const会检查错误。
#ifdef DEBUG
#else
#endif

// 高效打印(release模式下不会打印)
#ifdef DEBUG
#define YTLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define YTLog(...)
#endif


#pragma make 保存
// NSUserDefaults
#define YTUserDefaults [NSUserDefaults standardUserDefaults]
// NSUserDefaults获取
#define YTUserDefaultsObject(KEY)\
[[NSUserDefaults standardUserDefaults] objectForKey:KEY]
// NSUserDefaults保存
#define YTUserDefaultsSave(OBJECT,KEY) \
[[NSUserDefaults standardUserDefaults] setObject:OBJECT forKey:KEY];\
[[NSUserDefaults standardUserDefaults] synchronize];

#pragma make 通知NotificationCenter
#define YTNotificationCenter [NSNotificationCenter defaultCenter]

#pragma make 弱强引用
#define YTWeakSelf(type)  __weak typeof(type) weak##type = type;
#define YTStrongSelf(type)  __strong typeof(type) type = weak##type;

#pragma make device类型
#define YT_IS_IPHONE            ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
#define YT_IPHONE5S                (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define YT_IPHONE6                 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define YT_IPHONE6PLUS             (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0 || [[UIScreen mainScreen] bounds].size.width == 736.0)


#pragma make 图片
// 获取本地图片
#define YTGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]


#pragma make UI
// 需要横屏或者竖屏,获取屏幕宽度与高度
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
// 屏幕宽    
#define YTSCREEN_WIDTH ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.width)
// 屏幕高
#define YTSCREENH_HEIGHT ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.height)
// 屏幕Size
#define YTSCREEN_SIZE ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale):[UIScreen mainScreen].bounds.size)
#else
#define YTSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define YTSCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height
#define YTSCREEN_SIZE [UIScreen mainScreen].bounds.size
#endif

UI

// UI

// 屏幕的宽高
#define YTScreen_Width  [UIScreen mainScreen].bounds.size.width
#define YTScreen_Height [UIScreen mainScreen].bounds.size.height


// keyWindow
#define kWindow [UIApplication sharedApplication].keyWindow


// 设置圆角
#define YTViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];

// 设置边框
#define YTViewBorder(View, Width, Color)\
\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]];

// 设置圆角,边框
#define YTViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]];


// 16进制color
#define YTColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
// random color
#define YTRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
// rgb
#define YTRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
// rgba
#define YTRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]
// clearColor
#define YTClearColor [UIColor clearColor]


// 角度转弧度
#define LRDegreesToRadian(x) (M_PI * (x) / 180.0)
// 弧度转角度
#define LRRadianToDegrees(radian) (radian*180.0)/(M_PI)


// 加载状态栏网络菊花
#define kShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES
// 收起加载状态栏网络菊花
#define HideNetworkActivityIndicator()      [UIApplication sharedApplication].networkActivityIndicatorVisible = NO
// 设置加载状态栏网络菊花
#define NetworkActivityIndicatorVisible(x)  [UIApplication sharedApplication].networkActivityIndicatorVisible = x


// 添加背景View(Window上的)
#define kBackView         for (UIView *item in kWindow.subviews) { \
if(item.tag == 1100) \
{ \
[item removeFromSuperview]; \
UIView * aView = [[UIView alloc] init]; \
aView.frame = [UIScreen mainScreen].bounds; \
aView.tag = 1100; \
aView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3]; \
[kWindow addSubview:aView]; \
} \
} \
// 移除window背景View
#define kRemoveBackView         for (UIView *item in kWindow.subviews) { \
if(item.tag == 1100) \
{ \
[UIView animateWithDuration:0.4 animations:^{ \
item.alpha = 0.0; \
} completion:^(BOOL finished) { \
[item removeFromSuperview]; \
}]; \
} \
} \


// 添加背景View和转圈
#define kShowHUDAndActivity kBackView;[MBProgressHUD showHUDAddedTo:kWindow animated:YES];kShowNetworkActivityIndicator()
// 移除背景View和转圈
#define kHiddenHUDAndAvtivity kRemoveBackView;kHiddenHUD;HideNetworkActivityIndicator()
// 判断是否为iPhone (2方式)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"])
// 判断是否为iPad   (2方式)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPAD ([[[UIDevice currentDevice] model] isEqualToString:@"iPad"])
// 判断是否为ipod
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
// 判断是否为 iPhone 5SE
#define iPhone5SE [[UIScreen mainScreen] bounds].size.width == 320.0f && [[UIScreen mainScreen] bounds].size.height == 568.0f
// 判断是否为iPhone 6/6s
#define iPhone6_6s [[UIScreen mainScreen] bounds].size.width == 375.0f && [[UIScreen mainScreen] bounds].size.height == 667.0f
// 判断是否为iPhone 6Plus/6sPlus
#define iPhone6Plus_6sPlus [[UIScreen mainScreen] bounds].size.width == 414.0f && [[UIScreen mainScreen] bounds].size.height == 736.0f
// ios系统版本
#define IOS_SYSTEM_STRING [[UIDevice currentDevice] systemVersion]
// 判断 iOS 8 或更高的系统版本
#define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0)? (YES):(NO))


// 判断真机还是模拟器
#if (TARGET_IPHONE_SIMULATOR)
    // 模拟器
#else
    // 真机
#endif


// ARC和MRC
#if __has_feature(objc_arc)
    // ARC
#else
    // MRC
#endif


// 沙盒根路径 
#define YTHomePath NSHomeDirectory()
// Documents路径
#define YTDocumentPath [NSString stringWithFormat:@"%@/Documents",NSHomeDirectory()]
// Tmp路径
#define YTTmpPath NSTemporaryDirectory()
// Caches路径
#define YTCachePath [NSString stringWithFormat:@"%@/Library/Caches",NSHomeDirectory()]
// 
#define YTFilePath(path) [NSString stringWithFormat:@"%@/%@",YTDocumentPath,path]

// 当地语言
#define LRCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])


// GCD
// 运行期间仅执行一次
#define YT_DISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);
// 主线程中执行
#define YT_DISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);
// 全局(异步)线程中执行
#define YT_DISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);
4. AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // init
    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController=[self rootVC];
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    // 初始化配置 第三方,推送,用户设置
    [self setup];
    
    return YES;
}
5. Nav Tab

YTTabBarController.h

#import <UIKit/UIKit.h>
@interface YTTabBarController : UITabBarController
@end

YTTabBarController.m

#import "YTTabBarController.h"
#import "YTNavBarController.h"


@interface YTTabBarController ()
@end

@implementation YTTabBarController

// 第一次使用该类时调用
+(void)initialize{
    
    // 状态栏项(统一设置)
    UITabBarItem *barItem=[UITabBarItem appearance];
    // 状态栏项 文字的默认/选中颜色
    [barItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor  grayColor]} forState:UIControlStateNormal];
    [barItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor]} forState:UIControlStateSelected];
}

//
- (void)viewDidLoad {
    
    [super viewDidLoad];
  
    //
    NSArray *contentArr=@[@[@"VC1",@"title1",@"img1",@"imgSelect1"],@[@"VC2",@"title2",@"img2",@"imgSelect2"]];
    for(NSArray *arr in contentArr){
        
        UIViewController *vc=(UIViewController *)NSClassFromString(arr[0]);
        NSString *title=contentArr[1];
        NSString *imgName=contentArr[2];
        NSString *imgSelectName=contentArr[3];
        
        
        vc.title=title;
        vc.tabBarItem=[[UITabBarItem alloc]initWithTitle:title image:[[UIImage imageNamed:imgName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:imgSelectName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [self addChildViewController:[[YTNavBarController alloc]initWithRootViewController:vc]];
    }
}

YTNavBarController.h

#import <UIKit/UIKit.h>

@interface YTNavBarController : UINavigationController
@end

YTNavBarController.m

#import "YTNavBarController.h"

@interface YTNavBarController ()

@end

@implementation YTNavBarController


/**
 *  第一次使用这个类的时候会调用(1个类只会调用1次)
 */
+ (void)initialize{
    // 设置导航栏主题
    [self setupNavBarTheme];
}


/**
 *  设置导航栏主题
 */
+ (void)setupNavBarTheme{
    
    // 获取导航栏单例
    UINavigationBar *navBar = [UINavigationBar appearance];
    
    // 设置导航栏 文本颜色
    [navBar setTintColor:[UIColor whiteColor]];
    // 设置导航栏 背景色
    navBar.barTintColor=[UIColor blackColor];
    
    // 设置导航栏 是否半透明(默认:true,从屏幕左上角为坐标原点)(即使图片无透明也使其透明,设置barTintColor则不再透明
    navBar.translucent=true;
    
    // 隐藏导航栏 返回按钮文字(移到屏幕外)
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
    // 设置导航栏 标题
    [navBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    
    // 设置导航栏 返回按钮
//    [navBar setBackIndicatorImage:[UIImage imageNamed:@"backNavT"]];
//    [navBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"backNavT"]];
}



- (void)viewDidLoad{
    
    [super viewDidLoad];
}

/**
 *  状态栏文字颜色  白色
 */
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

/**
 *  重写这个方法,当控制器跳转时自动隐藏底部导航
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    viewController.hidesBottomBarWhenPushed = YES; // 系统TabBar
    [super pushViewController:viewController animated:animated];
}
-(UIViewController *)popViewControllerAnimated:(BOOL)animated{
    return [super popViewControllerAnimated:true];
}

-(NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated{
    return [super popToRootViewControllerAnimated:animated];
}
@end
6. 上线
         选择描述文件
         修改版本号
         将Scheme改为Release模式(不会编译NSLog代码)
         确保地址为线上

打包 
     Product | Archive(如果按钮灰色不可选,选择Generic iOS Device)
     Export | Store商店/Hoc测试  (该窗口 可通过Window | Orginizer打开)


itunes商店创建应用
    Apple Developer | itunes connect中创建应用
          App信息选择类别,副类别
          价格范围选0
          App
              介绍图片可以只放iPhone5.5(用plus模拟器跑一下 截5张)
              技术支持url
              icon要1024*1024 且不能有alpha透明
              关键词以英文逗号分隔
              构建版本(可通过 活动 查看提交版本是否被检测通过)
              选择分级  
              有登录则提供登录账号密码

上传
     Xcode |  Open Developer Tool | Application Loader 
    或者 右键Xcode | Open Developer Tool | Application Loader 
    使用了二次验证则登录密码需是登陆https://appleid.apple.com/account/manage | Generate Password 中输入任意字符串后获得的密码
注册测试设备
  1. 获取UDID(用于添加测试设备)
连接手机,弹出iTunesStore,点击手机图标 双击序列号 UDID

2.注册测试Devices

新建Devices 填写设备名 和UDID
发布证书
  1. 创建发布证书(用于创建描述文件)
发布证书(可用于:)
    AdHoc测试 (企业签名后,便可任何设备下载)
    Store发布
测试证书
    现在已经不需要下载,直接勾选General | Automatically manage signing
1.钥匙串访问 | 证书助理 | 从证书颁发机构请求证书
2.创建发布证书

之前只能创建1个,现在可以创建多个。
创建csr 第一步 创建csr 第二步 新建发布证书 选择AppStore and Ad Hoc 发布和测试 选择刚刚创建的csr 下载证书并双击

2.创建App Identifiers(用于创建描述文件)

新建App ID 填写App名 BundleID register done
  1. 创建描述文件
  发布选:AppStore 
  测试选:Ad Hoc

2者用的是同一个发布证书(App Store发布证书)
新建,右上角+ 选择AppStore 选择App ID 选择证书 填写描述文件名 下载并双击 选择描述文件
上一篇下一篇

猜你喜欢

热点阅读