Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >IOS5开发-控件位置适应屏幕旋转代码

IOS5开发-控件位置适应屏幕旋转代码

作者头像
阿新
发布于 2018-04-12 07:34:03
发布于 2018-04-12 07:34:03
1.5K00
代码可运行
举报
文章被收录于专栏:c#开发者c#开发者
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation 
                                duration:(NSTimeInterval)duration {
    if (toOrientation == UIInterfaceOrientationLandscapeLeft ||
        toOrientation == UIInterfaceOrientationLandscapeRight) {
        [UIView beginAnimations:nil context:NULL]; {
            [UIView setAnimationDuration:1.0];
        }
            [UIView setAnimationDelegate:self];
        [viewA setFrame:CGRectMake(?,?,?,?)];
        [viewB setFrame:CGRectMake(?,?,?,?)];
        [viewC setFrame:CGRectMake(?,?,?,?)];
        } [UIView commitAnimations];    
    } else if  (toOrientation == UIInterfaceOrientationPortrait ||
            toOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        [UIView beginAnimations:nil context:NULL]; {
            [UIView setAnimationDuration:1.0];
        }
        [UIView setAnimationDelegate:self];
        [viewA setFrame:CGRectMake(?,?,?,?)];
        [viewB setFrame:CGRectMake(?,?,?,?)];
        [viewC setFrame:CGRectMake(?,?,?,?)];
        } [UIView commitAnimations];    
/*
* 提示:该行代码过长,系统自动注释不进行高亮。一键复制会移除系统注释 
* }   // Source @ http://www.jailbyte.ca/safari/files/SpinView.zip////  UntitledViewController.h//  SpinView////  Created by Richard Vacheresse on 10-05-20.//  Copyfright jailByte.ca 2010. Use it anyway you like.//#import <UIKit/UIKit.h>@interface UntitledViewController : UIViewController{	//-view (the image) used for manipulation by the accelerometer	UIImageView *imageView;}@property (nonatomic, retain) UIImageView *imageView;- (IBAction) actionBtnOne;@end---------------------------------------------------------------------------////  UntitledViewController.m////  SpinView - this is an example of how to deal with the rotation of views via the accelerometer and the//  overridden method shouldAutorotateToInterfaceOrientation. this example uses an image view as the view//	that is being rotated; this imageview is created with the press of a button, the resulting action is to//	simply show the layer in the view. from there you start to spin the device and the updates follow. to reset//  the view you must press the home key and then restart the app; sorry, just too lazy to add anymore.////	**note: there is a bug to this solution, and it becomes apparent when using the device and the user rotates//	the phone quickly 180 degrees. i believe it may have something to do with when the floats that are used//	to hold the x and y values are updated while rotating; like it grabs the coordinates while spinnning past 90//	degrees. the next time you rotate the view, the view will correct itself.////  Created by Richard Vacheresse on 10-05-20.//  Copyfright jailByte.ca 2010. Use it anyway you like.//#import "UntitledViewController.h"@implementation UntitledViewController@synthesize imageView;- (void)viewDidLoad{    [super viewDidLoad];		//-create a button	UIButton *btnOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];	[btnOne setTitle: @"btnOne" forState: UIControlStateNormal];	[btnOne setFrame:CGRectMake(0.0f, 0.0f, 105.0f, 55.0f)];	[btnOne setCenter:CGPointMake(160.0f, 55.0f)];	[btnOne addTarget:self action:@selector(actionBtnOne) forControlEvents:UIControlEventTouchUpInside];	//-add it to the display	[self.view addSubview: btnOne];}////	actionBtnOne - initializes a UIImageView, sets the initial properties, add it to the display, then releases it.//	- (IBAction) actionBtnOne{	imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];	[imageView setImage:[UIImage imageNamed:@"image.png"]];	[imageView setAutoresizesSubviews: YES];	[self.view addSubview:imageView];	[imageView release];}////	shouldAutorotateToInterfaceOrientation - used to interact with the accelerometer; this is an overriden method.//	- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{	if ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)	{				//-set the center of the image from the dimensions of the display		//-x value is +10 due to status bar		[UIView beginAnimations: nil context: NULL];		[UIView setAnimationDuration: 0.25];		CGFloat x = self.view.bounds.size.height / 2 + 10;		CGFloat y = self.view.bounds.size.width / 2;		CGPoint center = CGPointMake( x, y); 		[imageView setCenter: center];		[UIView commitAnimations];				[UIView beginAnimations: nil context: NULL];		[UIView setAnimationDuration: 0.25];				//-this will keep it in the same position - always standing up		//CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI / 0.5);				//this will keep it standing up as in portrait however it will turn it upsidedown		//CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI / 1.0);				//this will change the view to be upside-down but in proper alignment with the landscape mode		//CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI / 2.0);				//this will change the view to be rightside-up in proper alignment with landscape mode		CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI / -2.0);				imageView.transform = transform;		[UIView commitAnimations];			}	else	{		//-set the center of the image from the dimensions of the display		//-x value is +10 due to status bar		[UIView beginAnimations: nil context: NULL];		[UIView setAnimationDuration: 0.25];		CGFloat x = self.view.bounds.size.height / 2 + 10;		CGFloat y = self.view.bounds.size.width / 2;		CGPoint center = CGPointMake( x, y); 		[imageView setCenter: center];		[UIView commitAnimations];				[UIView beginAnimations: nil context: NULL];		[UIView setAnimationDuration: 0.25];		CGAffineTransform move = CGAffineTransformMakeTranslation(0.0f, 0.0f);		imageView.transform = move;		CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI * 2);		imageView.transform = transform;		[UIView commitAnimations];	}	    // Return YES for supported orientations	return (interfaceOrientation == UIInterfaceOrientationPortrait ||			interfaceOrientation == UIInterfaceOrientationLandscapeRight ||			interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||			interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);}- (void)dealloc{	[imageView release];    [super dealloc];}//-the@end
*/
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2012-06-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
IOS开发系列——UIView专题之二:动画篇【整理,部分原创】
UIView视图的动画功能,可以使在更新或切换视图时有放缓节奏、产生流畅的动画效果,进而改善用户体验。UIView可以产生动画效果的变化包括:
江中散人_Jun
2022/03/08
1.8K0
iPhone开发小技巧
1、如果在程序中想对某张图片进行处理的话(得到某张图片的一部分)可一用以下代码:
用户2192970
2019/02/21
9290
iOS动画专题·UIView二维形变动画与CAAnimation核心动画(transform动画,基础,关键帧,组动画,路径动画,贝塞尔曲线)
总的来说,从涉及类的形式来看,iOS动画有:基于UIView的仿射形变动画,基于CAAnimation及其子类的动画,基于CG的动画。这篇文章着重总结前两种动画。
陈满iOS
2018/09/10
3.6K0
iOS动画专题·UIView二维形变动画与CAAnimation核心动画(transform动画,基础,关键帧,组动画,路径动画,贝塞尔曲线)
浅汇-iOS 动画
        在iOS开发中,制作动画效果是最让开发者享受的环节之一。一个设计严谨、精细的动画效果能给用户耳目一新的效果,吸引他们的眼光 —— 这对于app而言是非常重要的。我们总是追求更为酷炫的实现,如果足够仔细,我们不难发现一个好的动画通过步骤分解后本质上不过是一个个简单的动画实现。本文就个人搜集的一些动画相关的理论和实践知识做个小结,不足之处请勿见怪。
進无尽
2018/09/12
1K0
浅汇-iOS 动画
【IOS开发基础系列】UIView专题
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html
江中散人_Jun
2023/10/16
1.2K0
【IOS开发基础系列】UIView专题
【iOS学习】——手势识别
iOS 手势 1.如果一个控件继承于 UIControl,那么它将不需要手势 2.所有控件都可以添加手势 [控件 addGestureRecognizer: ] 3.iOS 系统提供的手势有哪些 UITapGestureRecognizer 点击 UISwipeGestureRecognizer 轻扫 UIPanGestureRecognizer 拖动 UIRotationGestureRecognizer 旋转 UIPinchGe
LeeCen
2018/10/11
1.9K0
【iOS学习】——手势识别
【IOS开发进阶系列】动画专题
http://doc.okbase.net/Hello_Hwc/archive/123447.html
江中散人_Jun
2023/10/16
8290
【IOS开发进阶系列】动画专题
老司机带你走进Core Animation 之图层的透视、渐变及复制
老司机的想法就是要把CoreAnimation头文件中的类大概都说一遍,毕竟一开始把系列名定成了《老司机带你走进CoreAnimation》(深切的觉得自己给自己坑了。。。)。
老司机Wicky
2018/08/22
8410
老司机带你走进Core Animation 之图层的透视、渐变及复制
实践-小效果 V
关键效果设置:在改变tableHeaderView的高度后,再手动调用下 Tb 的 setTableHeaderView方法。
進无尽
2018/09/12
1.3K0
实践-小效果 V
简单放置一张图片,实现放大缩小旋转效果1 image和imageView的区别2 创建控件显示到view上的标准步骤3 CGRectOffset函数的含义4 小飞机-监听四个按钮的点击事件(代码)5
1 image和imageView的区别 image是图片(照片). imageView是放图片的控件(相框). 2 创建控件显示到view上的标准步骤 创建对象. 设置内容. 设置大小. addsubview 3 CGRectOffset函数的含义 待补充 4 小飞机-监听四个按钮的点击事件(代码) -(void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
stanbai
2018/06/28
1.2K0
图层几何学 -- iOS Core Animation 系列二
《图层树和寄宿图 -- iOS Core Animation 系列一》介绍了图层的基础知识和一些属性方法。这篇主要内容是学习下图层在父图层上怎么控制位置和尺寸的。
Charlie_W
2018/10/19
7070
图层几何学 -- iOS Core Animation 系列二
Quartz2D复习(四) --- 图层CALayer和动画CAAnimation
1)、在ios中,能看得见摸得着的东西基本上都是UIView, 比如按钮、文本标签、文本输入框、图标等,这些都是UIView
tandaxia
2018/09/27
1.7K0
Quartz2D复习(四) --- 图层CALayer和动画CAAnimation
iOS学习——核心动画之Layer基础
CALayer我们又称它叫做层。在每个UIView内部都有一个layer这样一个属性,UIView之所以能够显示,就是因为它里面有这个layer才具有显示的功能。我们可以通过操作CALayer对象,可以很方便地调整UIView的一些外观属性,可以给UIView设置阴影,圆角,边框等等...
mukekeheart
2018/08/01
1.7K0
iOS学习——核心动画之Layer基础
iOS 动画基础总结篇
美女镇楼.JPG 好久没有更新简书了,最近在看一个动画的第三方,想着是时候可以把动画相关的东西总结下了!对了,上面的美女是龙母!哈哈,最近看权力游戏,感觉很好! -------------------------------------------------进入正题------------------------------------------------------------------ 动画的大体分类(个人总结可能有误) 分类.png UIView 动画 属性动画 [UIView beg
陈雨尘
2018/06/07
1.2K0
iOS屏幕旋转处理
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 被调用。这个方法是发生在翻转开始之前。一般用来禁用某些控件或者停止某些正在进行的活动,比如停止视频播放。 再来是
ppppy
2022/11/15
8860
UI篇-UITabBar及其相关其他知识
和UINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换。
進无尽
2018/09/12
2.3K0
UI篇-UITabBar及其相关其他知识
iOS 系统中的视图动画
动画为用户界面的状态转换提供了流畅的可视化效果, 在 iOS 中大量使用了动画效果, 包括改变视图位置、 大小、 从可视化树中删除视图, 隐藏视图等。 你可以考虑用动画效果给用户提供反馈或者用来实现有趣的特效。
beginor
2020/08/10
2.6K0
【 iOS 应用开发 】 UIKit 控件 ( UIView 属性 | storyboard 设置 | 模拟器 | 拖线关联 | tag | 软键盘操作 | 颜色值 | 代码生成控件 | 动画设置 )
LaunchScreen.storyboard 界面 : 该界面不是用于展示应用程序的界面 ;
韩曙亮
2023/03/27
5.6K0
【 iOS 应用开发 】 UIKit 控件 ( UIView 属性 | storyboard 设置 | 模拟器 | 拖线关联 | tag | 软键盘操作 | 颜色值 | 代码生成控件 | 动画设置 )
iOS动画系列之二:带时分秒指针的时钟动画(下)1. 创建CALayer2. 设置时分秒针3. 创建CADisplayLink4. 成稿
1. 创建CALayer position:默认情况下相当于UIView的center contents:CALayer的内容。可以设置为图片,但是需要桥接。桥接不需要自己额外设置,编译后编译器会自动提示,让Xcode自动帮我们桥接就可以啦。 就像添加子视图一样,别忘了把自己创建的Layer添加到view.layer上面。 - (void)viewDidLoad { [super viewDidLoad]; CALayer *dialLayer= [[CALayer allo
stanbai
2018/06/28
1K0
iOS Core Animation:Advanced Techniques
到目前为止,我们已经探讨过CALayer类了,同时我们也了解到了一些非常有用的绘图和动画功能。但是Core Animation图层不仅仅能作用于图片和颜色而已。本章就会学习其他的一些图层类,进一步扩展使用Core Animation绘图的能力。
conanma
2021/09/02
2.1K0
推荐阅读
相关推荐
IOS开发系列——UIView专题之二:动画篇【整理,部分原创】
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档