相关疑难解决方法(0)

可可:框架和边界之间有什么区别?

UIView及其子类都具有属性framebounds.有什么不同?

cocoa cocoa-touch uiview

567
推荐指数
9
解决办法
18万
查看次数

如何获得与方向相关的屏幕高度和宽度?

我正在尝试以编程方式确定我的应用程序的当前高度和宽度.我用这个:

CGRect screenRect = [[UIScreen mainScreen] bounds];
Run Code Online (Sandbox Code Playgroud)

但无论设备是纵向还是横向,这都会产生320的宽度和480的高度.如何确定主屏幕的当前宽度和高度(即取决于设备方向)?

ios

96
推荐指数
8
解决办法
8万
查看次数

IPhone/IPad:如何以编程方式获取屏幕宽度?

嗨,我想知道是否有办法以编程方式获得宽度.

我正在寻找足以容纳iphone 3gs,iphone 4,ipad的东西.此外,宽度应根据设备是纵向还是横向(对于ipad)而改变.

谁知道怎么做?我一直在寻找...谢谢!

iphone cocoa-touch objective-c ipad

81
推荐指数
3
解决办法
13万
查看次数

横向方向但纵向框架值?

我正在开发一个带有最新SDK的iOS应用程序.

我已将Landscape Right orientation设置为可用的唯一方向,我对viewController视图有疑问.

这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(deviceOrientationDidChange:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != AVCaptureVideoOrientationLandscapeRight);
}

- (void)deviceOrientationDidChange:(NSNotification*)notification
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (orientation == AVCaptureVideoOrientationLandscapeLeft)
        NSLog(@"Orientation: Landscape Left");
    else if (orientation == AVCaptureVideoOrientationLandscapeRight)
        NSLog(@"Orientation: Landscape Right");
    NSLog(@"FRAME: %@", NSStringFromCGRect(self.view.frame));
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的日志:

Orientation: Landscape Right
FRAME: {{0, 0}, {320, 568}}
Orientation: Landscape Right
FRAME: {{0, 0}, {320, 568}}
Run Code Online (Sandbox Code Playgroud)

我的问题是{{0, 0}, {320, 568}}:

为什么我会得到这些价值?

我认为正确的价值观是 …

objective-c frame ios

8
推荐指数
1
解决办法
4792
查看次数

UIView的帧大小问题

我正在开发一个iPad项目,目前它是在Landscape视图上.我试着这样做:

self.view.frame.size.height
Run Code Online (Sandbox Code Playgroud)

为什么这总是返回960?虽然在景观中,视图本身的高度尺寸应为768对吗?

我想要做的是allocInitWithFrame位于底部的UIToolbar.该UIToolBar有50的高度,所以这里是我所做的这些失败:

self.bottom_bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.frame.size.height-50, self.view.frame.size.width, 50)];
Run Code Online (Sandbox Code Playgroud)

为什么这样,我该怎么做?

iphone objective-c uiviewcontroller ipad ios

7
推荐指数
1
解决办法
6712
查看次数

iOS 6旋转错误:窗口和根视图控制器框架在旋转时不会改变

可能重复:
在iPhone中重新定位后"框架/窗口大小不正确"

我正在尝试使用我的应用程序解决一个非常令人沮丧的问题 - 在研究它时我可能在iOS中发现了一个错误:

旋转iPad时,视图会旋转,但它的框架不会改变.我正在运行一个计时器,每秒打印出我的视图的宽度和高度,虽然我可以看到视图在视觉上旋转,但框架仍然是"768x1024",无论如何.

来自Apple的文档:

当用户界面旋转时,将调整窗口大小以匹配新方向.窗口调整其根视图控制器的框架以匹配新大小,并且此大小依次沿视图层次结构传播到其他视图.

这正是未发生的事情,它给我带来了各种各样的麻烦.有谁知道如何修复旋转,以便框架改变?

重现步骤:

  1. 创建一个新的空项目
  2. 添加骨骼库存UIViewController作为根视图
  3. 设置计时器以打印根视图控制器的框架宽度和高度
  4. 运行您的应用,并将其全部旋转.这是我正在测试的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = [[UIViewController alloc] init];

    NSLog(@"%fx%f", self.window.rootViewController.view.frame.size.width, self.window.rootViewController.view.frame.size.height);

    // Add a label to confirm orientation
    UILabel *orientationLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,10,100,30)];
    orientationLabel.text = @"Top Left";
    [self.window.rootViewController.view addSubview: orientationLabel];

    [NSTimer scheduledTimerWithTimeInterval:.3 target:self selector:@selector(testScale) userInfo:nil repeats:YES];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
- (void) testScale {
    NSLog(@"%fx%f", self.window.rootViewController.view.frame.size.width, self.window.rootViewController.view.frame.size.height);
}

rotation ios ios6

5
推荐指数
1
解决办法
5144
查看次数