Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
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.5K0
iPhone开发小技巧
1、如果在程序中想对某张图片进行处理的话(得到某张图片的一部分)可一用以下代码:
用户2192970
2019/02/21
8150
浅汇-iOS 动画
        在iOS开发中,制作动画效果是最让开发者享受的环节之一。一个设计严谨、精细的动画效果能给用户耳目一新的效果,吸引他们的眼光 —— 这对于app而言是非常重要的。我们总是追求更为酷炫的实现,如果足够仔细,我们不难发现一个好的动画通过步骤分解后本质上不过是一个个简单的动画实现。本文就个人搜集的一些动画相关的理论和实践知识做个小结,不足之处请勿见怪。
進无尽
2018/09/12
8980
浅汇-iOS 动画
iOS动画专题·UIView二维形变动画与CAAnimation核心动画(transform动画,基础,关键帧,组动画,路径动画,贝塞尔曲线)
总的来说,从涉及类的形式来看,iOS动画有:基于UIView的仿射形变动画,基于CAAnimation及其子类的动画,基于CG的动画。这篇文章着重总结前两种动画。
陈满iOS
2018/09/10
3.4K0
iOS动画专题·UIView二维形变动画与CAAnimation核心动画(transform动画,基础,关键帧,组动画,路径动画,贝塞尔曲线)
简单放置一张图片,实现放大缩小旋转效果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.1K0
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
9790
实践-小效果 V
关键效果设置:在改变tableHeaderView的高度后,再手动调用下 Tb 的 setTableHeaderView方法。
進无尽
2018/09/12
1.1K0
实践-小效果 V
iOS 惯性滑动效果
最近公司SDK新搞了个功能,手势滑动地图后,要具备惯性滑动效果的功能。安卓是先做出来了,然后给我看,由于我早体验过某鸟地图,某鸟地图也有这种效果,加上安卓做得确实不错,还在忙着研究OpenGL的我也只
清墨
2018/05/07
3.4K0
iOS 惯性滑动效果
iOS 动画基础总结篇
美女镇楼.JPG 好久没有更新简书了,最近在看一个动画的第三方,想着是时候可以把动画相关的东西总结下了!对了,上面的美女是龙母!哈哈,最近看权力游戏,感觉很好! -------------------------------------------------进入正题------------------------------------------------------------------ 动画的大体分类(个人总结可能有误) 分类.png UIView 动画 属性动画 [UIView beg
陈雨尘
2018/06/07
1.1K0
iOS动画系列之一:带时分秒指针的时钟动画(上)1. 最终实现的效果以及思维导图2. CALayer3. 隐式动画
1. 最终实现的效果以及思维导图 实现的效果。不小心暴露了写文章的时间。-_-+++ 实现效果 实现的步骤思维导图: 思维导图.png 2. CALayer 其实今天分享的主角是CALayer。因为所
stanbai
2018/06/28
2.1K0
Core Animation实战三(图层几何学)
了解游戏的人一般都知道锚点,在UIView中我们很少用到。anchorPoint位于图层的中点,所以图层的将会以这个点为中心放置。anchorPoint属性并没有被UIView接口暴露出来,这也是视图的position属性被叫做“center”的原因。但是图层的anchorPoint可以被移动,比如你可以把它置于图层frame的左上角,于是图层的内容将会向右下角的position方向移动(图3.3),而不是居中了。
星宇大前端
2019/01/15
4270
老司机带你走进Core Animation 之图层的透视、渐变及复制
老司机的想法就是要把CoreAnimation头文件中的类大概都说一遍,毕竟一开始把系列名定成了《老司机带你走进CoreAnimation》(深切的觉得自己给自己坑了。。。)。
老司机Wicky
2018/08/22
7760
老司机带你走进Core Animation 之图层的透视、渐变及复制
iOS开发CoreAnimation解读之六——CATransform3D变换的应用
        CATransform3D定义了一个变化矩阵,通过对矩阵参数的设置,我们可以改变layer的一些属性,这个属性的改变,可以产生动画的效果。首先,CATransform3D定义了一个4*4的矩阵,如下:
珲少
2018/08/15
1.6K0
iOS开发CoreAnimation解读之六——CATransform3D变换的应用
图层几何学 -- iOS Core Animation 系列二
《图层树和寄宿图 -- iOS Core Animation 系列一》介绍了图层的基础知识和一些属性方法。这篇主要内容是学习下图层在父图层上怎么控制位置和尺寸的。
Charlie_W
2018/10/19
6360
图层几何学 -- iOS Core Animation 系列二
iOS 知识小集(横竖屏切换)
iOS 中横竖屏切换的功能,在开发iOS app中总能遇到。以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰到了,demo尝试了几种情况,这里就做下总结。 注意
Haley_Wong
2018/08/22
4.3K1
iOS 知识小集(横竖屏切换)
iOS动画-CAAnimation使用详解
理解了隐式动画后,显式动画就更加通俗易懂了。区别于隐式动画的特点,显式动画就是需要我们明确指定类型、时间等参数来实现效果的动画。除此之外,我们也可以创建非线性动画,比如沿着任意一条曲线运动等; 我们平时最常用的也是显式动画,不仅系统为我们的视图提供了UIViewAnimationWithBlock的动画封装,而且我们在熟悉了Core Animation的动画属性后也可以很方便的设置显式动画;
梧雨北辰
2019/05/07
2.4K0
iOS动画-CAAnimation使用详解
绘制图形的视图方式为_三角函数图象的平移变换
A view (an object whose class is UIView or a subclass of UIView) knows how to draw itself into a rectangular area of the interface.
全栈程序员站长
2022/08/04
6160
绘制图形的视图方式为_三角函数图象的平移变换
【iOS】今日头条的转场动画设置+手势控制
最近公司有个需求,做一个今日头条的用户动态的进入和退出的动画效果,并且退场时,可以自己点击退出,也可以手势下滑退出。头条的效果如下:
MapleYe
2020/03/31
1.9K0
【iOS】今日头条的转场动画设置+手势控制
iOS Core Animation:Advanced Techniques
到目前为止,我们已经探讨过CALayer类了,同时我们也了解到了一些非常有用的绘图和动画功能。但是Core Animation图层不仅仅能作用于图片和颜色而已。本章就会学习其他的一些图层类,进一步扩展使用Core Animation绘图的能力。
conanma
2021/09/02
1.9K0
UI篇-关于单个页面屏幕旋转要注意的问题
有时候,我们会需要在整个项目中,使某一个ViewController支持屏幕旋转,而其他的ViewController并不能自动旋转。这是一个很常见的需求,下面就屏幕旋转相关问题做个小结。
進无尽
2018/09/12
3.6K0
UI篇-关于单个页面屏幕旋转要注意的问题
推荐阅读
相关推荐
IOS开发系列——UIView专题之二:动画篇【整理,部分原创】
更多 >
领券
💥开发者 MCP广场重磅上线!
精选全网热门MCP server,让你的AI更好用 🚀
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验