Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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
Iphone 为什么更改方向时会剪切文本_Iphone_Uiwebview_Xcode4.2_Uiinterfaceorientation - Fatal编程技术网

Iphone 为什么更改方向时会剪切文本

Iphone 为什么更改方向时会剪切文本,iphone,uiwebview,xcode4.2,uiinterfaceorientation,Iphone,Uiwebview,Xcode4.2,Uiinterfaceorientation,我正在使用web视图显示HTML内容,并使用一些定向方法,但当我第一次将定向形式从横向更改为纵向时,文本从视图中消失。当我从纵向滚动到另一个页面时,它会完美地显示HTML内容。这可能是因为横向到纵向的宽度造成的肖像画 我使用的代码和方法如下: 设置页面大小 - (void)setPageSize:(NSString *)orientation { NSLog(@"• Set size for orientation: %@", orientation); pageWidth = screenB

我正在使用web视图显示HTML内容,并使用一些定向方法,但当我第一次将定向形式从横向更改为纵向时,文本从视图中消失。当我从纵向滚动到另一个页面时,它会完美地显示HTML内容。这可能是因为横向到纵向的宽度造成的肖像画

我使用的代码和方法如下:

设置页面大小

- (void)setPageSize:(NSString *)orientation {
NSLog(@"• Set size for orientation: %@", orientation);

pageWidth = screenBounds.size.width;
pageHeight = screenBounds.size.height;
if ([orientation isEqualToString:@"landscape"]) {
    pageWidth = screenBounds.size.height;
    pageHeight = screenBounds.size.width;
}
}

定向

- (NSString *)getCurrentInterfaceOrientation {
if ([availableOrientation isEqualToString:@"portrait"] || [availableOrientation isEqualToString:@"landscape"])
{
    return availableOrientation;
} 
else {
    // WARNING!!! Seems like checking [[UIDevice currentDevice] orientation] against "UIInterfaceOrientationPortrait" is broken (return FALSE with the device in portrait orientation)
    // Safe solution: always check if the device is in landscape orientation, if FALSE then it's in portrait.
    if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
        return @"landscape";
    } else {
        return @"portrait";
    }
}
}

}

}


请帮帮我。哪里出了问题。

我发现问题不在于代码,我已经更改了html页面的页面大小,现在可以正常工作。

您是否正确设置了webview的autoresize属性?是的,我已经将webview的autoresize设置为灵活的高度和宽度
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
if ([availableOrientation isEqualToString:@"portrait"]) {
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
} else if ([availableOrientation isEqualToString:@"landscape"]) {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
} else {
    return YES;
}   
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// Notify the index view
[indexViewController willRotate];

// Since the UIWebView doesn't handle orientationchange events correctly we have to do handle them ourselves 
// 1. Set the correct value for window.orientation property
NSString *jsOrientationGetter;
switch (toInterfaceOrientation) {
    case UIDeviceOrientationPortrait:
        jsOrientationGetter = @"window.__defineGetter__('orientation', function() { return 0; });";
        break;
    case UIDeviceOrientationLandscapeLeft:
        jsOrientationGetter = @"window.__defineGetter__('orientation', function() { return 90; });";
        break;
    case UIDeviceOrientationLandscapeRight:
        jsOrientationGetter = @"window.__defineGetter__('orientation', function() { return -90; });";
        break;
    case UIDeviceOrientationPortraitUpsideDown:
        jsOrientationGetter = @"window.__defineGetter__('orientation', function() { return 180; });";
        break;
    default:
        break;
}

// 2. Create and dispatch a orientationchange event    
NSString *jsOrientationChange = @"if (typeof bakerOrientationChangeEvent === 'undefined') {\
                                      var bakerOrientationChangeEvent = document.createEvent('Events');\
                                          bakerOrientationChangeEvent.initEvent('orientationchange', true, false);\
                                  }; window.dispatchEvent(bakerOrientationChangeEvent)";

// 3. Merge the scripts and load them on the current UIWebView
NSString *jsCommand = [jsOrientationGetter stringByAppendingString:jsOrientationChange];
[currPage stringByEvaluatingJavaScriptFromString:jsCommand];
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[indexViewController rotateFromOrientation:fromInterfaceOrientation toOrientation:self.interfaceOrientation];

[self setPageSize:[self getCurrentInterfaceOrientation]];
[self getPageHeight];    
[self resetScrollView];