iPhone 5 屏幕尺寸变长指南

本文介绍了一种方法来获取程序中视图的大小,并讨论了如何使用AutoLayout进行界面布局,以适应不同尺寸的屏幕,特别是针对iPhone5的设计调整。

原文地址:http://www.cnblogs.com/pinping/archive/2012/10/12.html(感谢原作者的奉献)

NSLog(@"applicationFrame%f",[UIScreenmainScreen].applicationFrame.size.height);

  可以的到整个程序的View的大小

    NSLog(@"navigationBar%f",self.navigationController.navigationBar.frame.size.height);

    NSLog(@"navigationBar%f",self.tabBarController.tabBar.frame.size.height);

 

floatheightEg = [UIScreenmainScreen].applicationFrame.size.height - self.navigationController.navigationBar.frame.size.height -self.tabBarController.tabBar.frame.size.height;

LeftView*lView=[[LeftView alloc] initWithFrame:CGRectMake(0, 0, 56, heightEg) Number:1];

    [self.view addSubview:lView];

 

现在的lView就个适用iPhone 4/S 和iPhone 5那;

因为的程序里面有navigationController和tabBarController所以要减去navigationController和tabBarController的高度;

 

 

posted @ 2012-10-12 15:03 程序是啥 阅读(672) 评论(0) 编辑

来自:http://www.devdiv.com/iOS_6_Auto_Layout_NSLayoutConstraint_界面布局-weblog-227936-13173.html

终于ios 6推出了正式版本,同时也随之iphone5的面试,对于ios开发者来说,也许会感觉到一些苦恼。那就是原本开发的程序,需要大量的修改了。为了适应最新的iphone5的屏幕。

在WWDC2012里苹果推出了,Auto Layout的概念。我们可以通过Auto Layout来适应屏幕的改变。

比如我们要做一个如下的界面。

如果按照以前的frame的方式的话,大概代码如下

 

[代码]c#/cpp/oc代码:

01UIView *myview = [[UIView alloc] init];
02myview.backgroundColor = [UIColor greenColor];
03UIView *redView = [[UIView alloc] init];
04redView.backgroundColor = [UIColor redColor];
05UIView *blueView = [[UIView alloc] init];
06blueView.backgroundColor = [UIColor blueColor];
07[myview addSubview:redView];
08[myview addSubview:blueView];
09redView.frame = CGRectMake(50, 80, 100, 30);
10blueView.frame = CGRectMake(180, 80, 100, 30);
11self.view = myview;

通过上面的代码我们就能很简单的实现上面的布局效果了,但是使用auto layout的时候我们需要使用如下代码来实现。

 

 

[代码]c#/cpp/oc代码:

01UIView *myview = [[UIView alloc] init];
02 
03myview.backgroundColor = [UIColor greenColor];
04 
05UIView *redView = [[UIView alloc] init];
06 
07redView.backgroundColor = [UIColor redColor];
08 
09UIView *blueView = [[UIView alloc] init];
10 
11blueView.backgroundColor = [UIColor blueColor];
12 
13[myview addSubview:redView];
14 
15[myview addSubview:blueView];
16 
17[myview setTranslatesAutoresizingMaskIntoConstraints:NO];
18 
19[redView setTranslatesAutoresizingMaskIntoConstraints:NO];
20 
21[blueView setTranslatesAutoresizingMaskIntoConstraints:NO];
22 
23NSMutableArray *tmpConstraints = [NSMutableArray array];
24 
25[tmpConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"|-50-[redView(==100)]-30-[blueView(==100)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(redView,blueView)]];
26 
27[tmpConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-30-[redView(==30)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(redView)]];
28 
29[tmpConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-30-[blueView(==redView)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(blueView,redView)]];
30 
31[myview addConstraints:tmpConstraints];
32 
33self.view = myview;

最后对于向下兼容的时候我们可以通过

 

 

[代码]c#/cpp/oc代码:

1if([myview respondsToSelector:@selector(addConstraints:)]){
2 
3//支持auto layout
4 
5}else{
6 
7//不支持
8 
9}


【电动汽车充电站有序充电调度的分散式优化】基于蒙特卡诺和拉格朗日的电动汽车优化调度(分时电价调度)(Matlab代码实现)内容概要:本文介绍了基于蒙特卡洛和拉格朗日方法的电动汽车充电站有序充电调度优化方案,重点在于采用分散式优化策略应对分时电价机制下的充电需求管理。通过构建数学模型,结合不确定性因素如用户充电行为和电网负荷波动,利用蒙特卡洛模拟生成大量场景,并运用拉格朗日松弛法对复杂问题进行分解求解,从而实现全局最优或近似最优的充电调度计划。该方法有效降低了电网峰值负荷压力,提升了充电站运营效率与经济效益,同时兼顾用户充电便利性。 适合人群:具备一定电力系统、优化算法和Matlab编程基础的高校研究生、科研人员及从事智能电网、电动汽车相关领域的工程技术人员。 使用场景及目标:①应用于电动汽车充电站的日常运营管理,优化充电负荷分布;②服务于城市智能交通系统规划,提升电网与交通系统的协同水平;③作为学术研究案例,用于验证分散式优化算法在复杂能源系统中的有效性。 阅读建议:建议读者结合Matlab代码实现部分,深入理解蒙特卡洛模拟与拉格朗日松弛法的具体实施步骤,重点关注场景生成、约束处理与迭代收敛过程,以便在实际项目中灵活应用与改进。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值