Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XCode更改背景图像并更改方向_Xcode_Uiwebview_Background Image_Device Orientation - Fatal编程技术网

XCode更改背景图像并更改方向

XCode更改背景图像并更改方向,xcode,uiwebview,background-image,device-orientation,Xcode,Uiwebview,Background Image,Device Orientation,我有一个iPhone应用程序,由一个显示网站的UIWebView组成。在UIWebView在我的ViewController.m文件中完成加载后,我已将背景图像设置为UIWebView,如下所示: - (void)webViewDidFinishLoad:(UIWebView *)webView { // Set UIWebView Background Image self->webView.backgroundColor = [UIColor colorWithPa

我有一个iPhone应用程序,由一个显示网站的UIWebView组成。在UIWebView在我的
ViewController.m
文件中完成加载后,我已将背景图像设置为UIWebView,如下所示:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
     // Set UIWebView Background Image
     self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-portrait.png"]];
}
当设备处于纵向时,这很好,但是如果用户将设备方向切换为横向,我想更改背景图像,如果再次切换,则返回纵向,等等

我写了下面的代码,但我不确定该放在哪里(因为它需要在他们切换方向时更改背景图像;而不仅仅是一次):


我怎样才能做到这一点?如果你能给我代码并指出放在哪里,那将是一个很大的帮助:)

在视图控制器中重写这些方法之一,并将代码放在那里

将此代码放入ViewController.m中

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation
{
    // Set UIWebView Background Image
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
    {
        // code for Portrait orientation  
        self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-portrait.png"]];
    }
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
    {
        // code for landscape orientation  
        self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-landscape.png"]];
    }
}

你能给我看看代码吗?把它放在哪里?我只使用Xcode和Objective C大约一周了。。。不过我很快就明白了。我找到了答案(使用DidRotateFrominerFaceOrientation)。谢谢你为我指明了正确的方向!:)我添加了示例,但为时已晚:)好吧,也许你可以帮个忙:横向背景图像的尺寸是多少?我原以为是920x640(视网膜),但当我使用这个尺寸时,图像底部(横向)似乎被切断了。它是960x640,但从这些尺寸中,你需要减去状态栏的高度(视网膜中的20pt->40px)和任何工具栏、导航栏、选项卡栏的高度。所以,如果您是横向的,并且您的应用程序显示状态栏,那么它将是960x600(以像素为单位)
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation
{
    // Set UIWebView Background Image
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
    {
        // code for Portrait orientation  
        self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-portrait.png"]];
    }
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
    {
        // code for landscape orientation  
        self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-landscape.png"]];
    }
}