Iphone 的定位?
我正在编写以下代码
- (void)viewDidLoad
{
[super viewDidLoad];
[self checkOrientation];
}
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
[super viewWillDisappear:animated];
}
- (void)receivedRotate:(NSNotification *)notification
{
[self checkOrientation];
}
-(void)checkOrientation
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
{
NSLog(@"Right and Left");
self.view.frame = CGRectMake(0, 0, 480, 320);
// Set x coorinate of views you want to change
}
else
{
NSLog(@"Up or Down");
// Set x coordinates of views to initial x xoordinates.
}
}
这条线
self.view.frame = CGRectMake(0, 0, 480, 320);
不起作用,如果我像
self.view.superview.frame = CGRectMake(-50, -70, 800, 900);
这样写它正在改变轴,但我不知道它的行为方式,
我想改变视图矩形,它的改变会改变方向,我该怎么做?
I am writing the following code
- (void)viewDidLoad
{
[super viewDidLoad];
[self checkOrientation];
}
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
[super viewWillDisappear:animated];
}
- (void)receivedRotate:(NSNotification *)notification
{
[self checkOrientation];
}
-(void)checkOrientation
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
{
NSLog(@"Right and Left");
self.view.frame = CGRectMake(0, 0, 480, 320);
// Set x coorinate of views you want to change
}
else
{
NSLog(@"Up or Down");
// Set x coordinates of views to initial x xoordinates.
}
}
This line
self.view.frame = CGRectMake(0, 0, 480, 320);
is not working, and If I will write like
self.view.superview.frame = CGRectMake(-50, -70, 800, 900);
then it is changing the axis, but I don't know how it is behaving,
I want to change the view rect change with it will change the orientations, how can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要使用通知进行轮换。您可以使用其中任何一个
您可以在
UIVIewController
上的参考文档Why are you going for Notifications for rotations. You can make use of any of these
You can find more details in the reference documents on
UIVIewController
为什么你要自己做一个函数来检查方向。相反,请使用 UIViewController 本身的函数。
Why are you checking the orientation by making a function by yourselves. Instead, use the function for the UIViewController itself.