您的位置:首页 > 其它

关于edgesForExtendedLayout和automaticallyAdjustsScrollViewInsets

2015-10-16 10:14 441 查看
拿UIScrollView来举例,在含有导航栏的页面内, self.edgesForExtendedLayout = UIRectEdgeNone; 调整的是UIScrollView本身的位置,self.automaticallyAdjustsScrollViewInsets
= NO;调整的是UIScrollView显示内容的位置。
在iOS7之后self.edgesForExtendedLayout 默认值UIRectEdgeAll,此时坐标原点在屏幕左上角
,在设置self.edgesForExtendedLayout = UIRectEdgeNone
会使坐标原点在导航栏左下角也就是说坐标原点回和iOS6一样,从这点来说设置self.edgesForExtendedLayout = UIRectEdgeNone达到的效果和设置
self.navigationController.navigationBar.translucent = NO效果一样。 self.edgesForExtendedLayout = UIRectEdgeNone是会对整个页面的控件的坐标起到作用的,而self.automaticallyAdjustsScrollViewInsets
= NO 是只针对于UIScrollView的。
举个例子
//
//  AppDelegate.h
//  TES
//
//  Created by sjkx123456 on 15/4/2.
//  Copyright (c) 2015年 sjkx123456. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

//
//  AppDelegate.m
//  TES
//
//  Created by sjkx123456 on 15/4/2.
//  Copyright (c) 2015年 sjkx123456. All rights reserved.
//

#import "AppDelegate.h"
#import "RootViewController.h"
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

RootViewController * rootVC = [[RootViewController alloc] init];
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:rootVC];
//    nav.navigationBar.translucent = NO;
//    nav.navigationBar.hidden = YES;
self.window.rootViewController = nav;

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

//
//  RootViewController.h
//  TES
//
//  Created by sjkx123456 on 15/4/2.
//  Copyright (c) 2015年 sjkx123456. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
UITableView * _goodsTabView;
}
@end


<pre name="code" class="objc">//
//  RootViewController.m
//  TES
//
//  Created by sjkx123456 on 15/4/2.
//  Copyright (c) 2015年 sjkx123456. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
//    self.edgesForExtendedLayout = UIRectEdgeNone;

//    self.automaticallyAdjustsScrollViewInsets = NO;
_goodsTabView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,240) style:UITableViewStylePlain];

_goodsTabView.rowHeight = 44;
_goodsTabView.dataSource = self;
_goodsTabView.delegate = self;
_goodsTabView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_goodsTabView.backgroundColor = [UIColor redColor];
[self.view addSubview:_goodsTabView];

//    UIView * v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
//    v.backgroundColor = [UIColor orangeColor];
//    [self.view addSubview:v];
}

#pragma mark UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellID = @"cellID";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.backgroundColor = [UIColor blueColor];
}
cell.textLabel.text = [NSString stringWithFormat:@"%d",indexPath.row];
return cell;

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end




如果self.edgesForExtendedLayout和self.automaticallyAdjustsScrollViewInsets都是默认值的情况下程序运行效果是这样的


如果self.edgesForExtendedLayout = UIRectEdgeNone;



 同时设置 self.edgesForExtendedLayout = UIRectEdgeNone;self.automaticallyAdjustsScrollViewInsets = NO;



只self.automaticallyAdjustsScrollViewInsets= NO;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: