无法理解iphone编程中的方向?
我在 ViewDidLoad 中编写代码如下,
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
//Whenever the device orientation changes, orientationChanged will be called
orientationChanged: 方法的主体如下
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
NSLog(@"Method is Called");
self.view.frame = CGRectMake(0, 0, 480, 320);
//self.view.superview.frame = CGRectMake(-50, -70, 800, 900);
//Based upon which orientation the device is in, update your View rotations.
//A simple view.transform = CGAffineTransformMakeRotation(whatever); will work well.
}
我无法理解该方法的行为,任何人都可以告诉我这两行会做什么,第一行改变 self.frame 的框架。 view.frame 和我评论过的 superview 的第二个。
提前致谢 萨恩
I am writing code in ViewDidLoad as following,
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
//Whenever the device orientation changes, orientationChanged will be called
and the body of orientationChanged: Method is following
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
NSLog(@"Method is Called");
self.view.frame = CGRectMake(0, 0, 480, 320);
//self.view.superview.frame = CGRectMake(-50, -70, 800, 900);
//Based upon which orientation the device is in, update your View rotations.
//A simple view.transform = CGAffineTransformMakeRotation(whatever); will work well.
}
I am unable to understand the behavior of this method, can any body tell me that what these two lines will do, the first one change frame of self.view.frame, and second one for superview which I did commented.
Thanks in Advance Saeen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以根据方向管理您的视图。检查我的答案这里< /strong>。
You can manage your views according to orientation. Check my answer here.
每当您旋转设备时都会调用此方法,您可以在此方法中设置框架
this metod will call when ever you rotate the device you can set frame in this method
使用这个通知中心它工作正常
use this insted of notification center it work fine