ios UIKit框架分析 第8天

1.viewController

->部分属性详解

@property(nonatomic,assign)UIModalTransitionStyle modalTransitionStyleNS_AVAILABLE_IOS(3_0);

typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {

    UIModalTransitionStyleCoverVertical =0呈现时沿垂直方向由底推出,关闭时从底部消失。

    UIModalTransitionStyleFlipHorizontal, 水平翻转,呈现时从右往左翻转;关闭时从左往右翻转。

    UIModalTransitionStyleCrossDissolve,两个视图交叉淡入淡出。

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2

    UIModalTransitionStylePartialCurl, 呈现时模态视图卷起一个边角翻页,关闭时模态视图翻回来。

#endif

};


@property(nonatomic,assign)UIModalPresentationStyle modalPresentationStyleNS_AVAILABLE_IOS(3_2);

这四种方式在iPad上面统统有效,但在iPhone和iPod touch上面系统始终以UIModalPresentationFullScreen模式

typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {

    UIModalPresentationFullScreen = 0全屏状态,这是默认的呈现style。iPhone只能全屏呈现

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2

    UIModalPresentationPageSheet, 它的宽度是768点,iPad横屏时非全屏,竖屏时全屏。

    UIModalPresentationFormSheet, 高度和宽度均会小于屏幕尺寸,居中显示,四周留下变暗区域。

    UIModalPresentationCurrentContext,弹出方式和presenting VC的父VC的方式相同。

#endif

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0

    UIModalPresentationCustom,

    UIModalPresentationNone = -1,        

#endif        

};


2.UIWebView

@property (nonatomic)BOOL suppressesIncrementalRendering

这个值决定了网页内容的渲染是否在把内容全部加载到内存中再去处理。

如果设置为YES,只有网页内容加载到内存里了才会去渲染


@property (nonatomic)UIWebPaginationMode paginationMode

分页显示的模式

typedef NS_ENUM(NSInteger, UIWebPaginationMode) {

    UIWebPaginationModeUnpaginated,

    UIWebPaginationModeLeftToRight,//左到右

    UIWebPaginationModeTopToBottom,

    UIWebPaginationModeBottomToTop,

    UIWebPaginationModeRightToLeft

};



加载网页

- (void)loadRequest:(NSURLRequest *)request;


加载html字符

- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL;

NSString *html = @"hello <h1>world<h1>"; 
[webView loadHTMLString:html baseURL:nil];

加载word、execl 、pdf常见文本类型

- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;

NSString *thePath = [[NSBundle mainBundle] pathForResource:@"iPhone_User_Guide" ofType:@"pdf"];
    if (thePath) {
        NSData *pdfData = [NSData dataWithContentsOfFile:thePath];
        [(UIWebView *)self.view loadData:pdfData MIMEType:@"application/pdf"
            textEncodingName:@"utf-8" baseURL:nil];
    }


webView 与 script 交互函数

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script;

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //获取html 页面的链接
    NSString * href = [webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
    NSLog(@"url is %@",href);
    
    //获取html 页面的标题
    NSString * title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    NSLog(@"title is %@",title);
    
    //设置html 页面 的输入框 的内容
     NSString *js_result = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('q')[0].value='ios';"];
     NSLog(@"result is %@",js_result);
}


3.UIWindow

-》@property(nonatomic) UIWindowLevel  windowLevel 详解

原文出处:http://www.cnblogs.com/smileEvday/archive/2012/03/27/2420362.html

UIWindow在显示的时候会根据UIWindowLevel进行排序的,即Level高的将排在所有Level比他低的层级的前面。下面我们来看UIWindowLevel的定义:

    const UIWindowLevel UIWindowLevelNormal;
    const UIWindowLevel UIWindowLevelAlert;
    const UIWindowLevel UIWindowLevelStatusBar;
    typedef CGFloat UIWindowLevel;

  IOS系统中定义了三个window层级,其中每一个层级又可以分好多子层级(从UIWindow的头文件中可以看到成员变量CGFloat _windowSublevel;),不过系统并没有把则个属性开出来。UIWindow的默认级别是UIWindowLevelNormal,我们打印输出这三个level的值分别如下:

2012-03-27 22:46:08.752 UIViewSample[395:f803] Normal window level: 0.000000
2012-03-27 22:46:08.754 UIViewSample[395:f803] Alert window level: 2000.000000
2012-03-27 22:46:08.755 UIViewSample[395:f803] Status window level: 1000.000000

  这样印证了他们级别的高低顺序从小到大为Normal < StatusBar < Alert,下面请看小的测试代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor yellowColor];
    [self.window makeKeyAndVisible];
    
    UIWindow *normalWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    normalWindow.backgroundColor = [UIColor blueColor];
    normalWindow.windowLevel = UIWindowLevelNormal;
    [normalWindow makeKeyAndVisible];
    
    CGRect windowRect = CGRectMake(50,
                                   50,
                                   [[UIScreen mainScreen] bounds].size.width - 100,
                                   [[UIScreen mainScreen] bounds].size.height - 100);
    UIWindow *alertLevelWindow = [[UIWindow alloc] initWithFrame:windowRect];
    alertLevelWindow.windowLevel = UIWindowLevelAlert;
    alertLevelWindow.backgroundColor = [UIColor redColor];
    [alertLevelWindow makeKeyAndVisible];
    
    UIWindow *statusLevelWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 50, 320, 20)];
    statusLevelWindow.windowLevel = UIWindowLevelStatusBar;
    statusLevelWindow.backgroundColor = [UIColor blackColor];
    [statusLevelWindow makeKeyAndVisible];
    
    NSLog(@"Normal window level: %f", UIWindowLevelNormal);
    NSLog(@"Alert window level: %f", UIWindowLevelAlert);
    NSLog(@"Status window level: %f", UIWindowLevelStatusBar);
    
    return YES;
}

我们可以注意到两点:

  1)我们生成的normalWindow虽然是在第一个默认的window之后调用makeKeyAndVisible,但是仍然没有显示出来。这说明当Level层级相同的时候,只有第一个设置为KeyWindow的显示出来,后面同级的再设置KeyWindow也不会显示。

  2)statusLevelWindow在alertLevelWindow之后调用makeKeyAndVisible,仍然只是显示在alertLevelWindow的下方。这说明UIWindow在显示的时候是不管KeyWindow是谁,都是Level优先的,即Level最高的始终显示在最前面。

  那么如何才能将后加的同一层级的window显示出来呢?

解决方案:

你可以试着把后面要显示的window的level设置成前面一个window的level值加一,这样也是可以。因为观察每个level都是1000对齐的,也就是说我们可以在中间弄一些subLevel出来 
经过测试 normalWindow.windowLevel = UIWindowLevelNormal+1;
确实可以

4.NSLayoutConstraint

设置view在父视图中的位置适应屏幕变换

首先说按比例缩放,这是在Interface Builder中无法设置的内容。而在代码中,使用NSLayoutConstraint类型的初始化函数中的multiplier参数就可以非常简单的设置按比例缩放。同时也可以设置不同NSLayoutAttribute参数来达到意想不到的效果,比如“A的Width等于B的Height的2倍”这样的效果。

详情参考:http://blog.csdn.net/djl4104804/article/details/20768901


5.NSTextAttachment 文本附件

-》TextKit实现图文混排

TextKit 详解 请点击http://www.cocoachina.com/applenews/devnews/2013/1113/7342.html

Textkit是iOS7新推出的类库,其实是在之前推出的CoreText上的封装,有了这个TextKit,以后不用再拿着CoreText来做累活了,根据苹果的说法,他们开发了两年多才完成,而且他们在开发时候也将表情混排作为一个使用案例进行研究,所以要实现表情混排将会非常容易。     TextKit并没有新增的类,他是在原有的文本显示控件上的封装,可以使用平时我们最喜欢使用的UILabel,UITextField,UITextView里面就可以使用了。
     

1.NSAtrributedString
          这是所有TextKit的载体,所有的信息都会输入到NSAttributedString里面,然后将这个String输入到Text控件里面就可以显示了。
    

 2.NSTextAttachment
     iOS7新增的类,作为文本的附件,可以放文件,可以放数据,以 NSAttachmentAttributeName这个key放入NSAttributedString里面,在表情混排这里,我们将放入image。
   

 3.重载NSTextAttachment
     本来是可以直接使用NSTextAttachment,但是我们需要根据文字大小来改变表情图片的大小,于是我们需要重载NSTextAttachment,NSTextAttachment实现了NSTextAttachmentContainer,可以给我们改变返回的图像,图像的大小。
     重载NSTextAttachment代码:

@interface MMTextAttachment : NSTextAttachment
{
}
@end

@implementation MMTextAttachment
//I want my emoticon has the same size with line's height
- (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex NS_AVAILABLE_IOS(7_0)
{
    return CGRectMake( 0 , 0 , lineFrag.size.height , lineFrag.size.height );
}
@end

    NSMutableAttributedString *str=[[NSMutableAttributedString alloc] initWithString:@"fdsahfjdsafkdhafjkhadjksfhjk" attributes:nil];
    
    MMTextAttachment *attachment=[[NSTextAttachment alloc] initWithData:nil ofType:nil];
    UIImage *img=[UIImage imageNamed:@"qrcode.png"];
    attachment.image=img;
    attachment.bounds=CGRectMake(0, -10, 20, 20);
    NSAttributedString *text=[NSAttributedString attributedStringWithAttachment:attachment];
    [str insertAttributedString:text atIndex:2];
    self.textView.attributedText=str;

效果如下:







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值