我正在开发一个项目,我在UIscrollview中添加了UIWebviews以显示描述。我这样做是因为我想添加滑动效果以移动到新的描述页面。现在,我想调整UIscrollview及其内容(即uiwebview),当方向改变时(即纵向到横向或反向)。
请给我任何示例代码或任何建议。
答案 0 :(得分:1)
要调整webview的大小,您必须写: -
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
webview.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * someValue1,
scrollView.frame.size.height * someValue2);
}
答案 1 :(得分:0)
您可以将代码放在以下代码块中:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if ([self isPadPortrait]) {
// Your code for Portrait
// set frame here
} else if ([self isPadLandscape]) {
// Your code for Landscape
// set frame here
}
以下代码将负责方向更改:
- (BOOL)isPadPortrait
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationPortrait
|| self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
- (BOOL)isPadLandscape
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
}
答案 2 :(得分:0)
您可以设置scrollView的autoresizingMask,并根据您的要求将此代码添加到.m文件中。
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * someValue1,
scrollView.frame.size.height * someValue2);
}
答案 3 :(得分:0)
当方向改变时
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
// this delegate method will called if we set should auto orientation return yes;
when ever we changed orientation so set frames..
}
例如
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
appDelegate.interface=interfaceOrientation;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// SET FRAMES FOR LANDSCAPE HERE
}
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationPortrait)
{
//SET FRAMES FOR Portrait HERE
}
}
答案 4 :(得分:0)
以下是类似问题及其解决方案的链接: Scale image to fit screen on iPhone rotation
他们使用AutoresizingMasks和ContentModes的组合来同时使用ScrollView和ImageView,尽管我认为相同的解决方案适用于您的WebView。