我正在一个项目中,我已经在UIscrollview中添加UIWebviews来显示说明。我这样做是因为我想添加滑动效果来移动到新的描述页面。现在,我想调整UIscrollview及其内容(即uiwebview),当方向改变时(即纵向到横向或Viceversa)。如何调整uiscrollview及其内容在iPhone中的方向变化?
请给我任何示例代码或任何建议。
我正在一个项目中,我已经在UIscrollview中添加UIWebviews来显示说明。我这样做是因为我想添加滑动效果来移动到新的描述页面。现在,我想调整UIscrollview及其内容(即uiwebview),当方向改变时(即纵向到横向或Viceversa)。如何调整uiscrollview及其内容在iPhone中的方向变化?
请给我任何示例代码或任何建议。
你可以把你的代码下面的代码块:
- (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));
}
您可以设置滚动视图的autoresizingMask并添加此代码根据您的要求将其添加到.m文件中。
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * someValue1,
scrollView.frame.size.height * someValue2);
}
它是否会调整uiwebview的大小,这是uiscrollview的内容 –
如果您在xib文件中制作视图的速度比通过旋转视图来测试视图要好,否则您需要创建一个转储xib文件来检查您需要的autoresizingMask应用 – Robin
当过方向改变
- (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
}
}
下面是一个类似的问题,他们的解决方案的链接: Scale image to fit screen on iPhone rotation
他们使用的组合S的AutoresizingMasks和ContentModes crollView,在他们的情况下,一个ImageView,但我想象相同的解决方案将适用于您的WebView。
要调整,你必须编写web视图: -
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
webview.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * someValue1,
scrollView.frame.size.height * someValue2);
}
准确地说,我是这个领域的新手,但我想知道如果你不使用void,那么在它将返回值为主要@shweta – SagarPPanchal
好作品,@shweta :) – SagarPPanchal
感谢它。我能够检测方向。但问题是调整UIscrollview及其内容。 Plz在那里帮助我。 –
你可以在'willAnimateRotationToInterfaceOrientation:'中设置你的框架。你还需要什么 ? – Devang
我只与我滚动视图,我想改变其内容的大小。怎么做? –