Използвам уеб изгледа, за да покажа 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";
}
}
}
- (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];
моля, помогнете ми. Къде бъркам.