Objective c 水平分页的UIScrollView,每个视图之间有一个间隙--视图不为';t中心
苹果的WWDC 2010教程视频“使用滚动视图设计应用程序”在iOS 4上运行良好,但在iOS 5上,页面不居中: 看来Objective c 水平分页的UIScrollView,每个视图之间有一个间隙--视图不为';t中心,objective-c,gaps-in-visuals,Objective C,Gaps In Visuals,苹果的WWDC 2010教程视频“使用滚动视图设计应用程序”在iOS 4上运行良好,但在iOS 5上,页面不居中: 看来 pagingScrollViewFrame.origin.x -= PADDING; 在iOS 5中不起作用 我的代码如下: #import "ViewController.h" @interface ViewController () @end @implementation ViewController #define PADDING 10 - (void
pagingScrollViewFrame.origin.x -= PADDING;
在iOS 5中不起作用
我的代码如下:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
#define PADDING 10
- (void)loadView
{
// Step 1: make the outer paging scroll view
CGRect pagingScrollViewFrame = [[UIScreen mainScreen] bounds];
pagingScrollViewFrame.origin.x -= PADDING;
pagingScrollViewFrame.size.width += (2 * PADDING);
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(pagingScrollView.bounds.size.width * 6, pagingScrollView.bounds.size.height);
pagingScrollView.delegate = self;
self.view = pagingScrollView;
for(int i = 0; i < 6; i++)
{
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor blueColor];
CGRect bounds = pagingScrollView.bounds;
CGRect pageFrame = bounds;
pageFrame.size.width -= (2 * PADDING);
pageFrame.origin.x = (bounds.size.width * i) + PADDING;
view.frame = pageFrame;
[pagingScrollView addSubview:view];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
#导入“ViewController.h”
@界面视图控制器()
@结束
@实现视图控制器
#定义填充10
-(void)负荷视图
{
//步骤1:创建外部分页滚动视图
CGRect pagingScrollViewFrame=[[UIScreen mainScreen]边界];
pagingScrollViewFrame.origin.x-=填充;
pagingScrollViewFrame.size.width+=(2*填充);
pagingScrollView=[[UIScrollView alloc]initWithFrame:pagingScrollViewFrame];
pagingScrollView.PaginEnabled=是;
pagingScrollView.backgroundColor=[UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator=否;
pagingScrollView.ShowShorizontalScrolIndicator=否;
pagingScrollView.contentSize=CGSizeMake(pagingScrollView.bounds.size.width*6,pagingScrollView.bounds.size.height);
pagingScrollView.delegate=self;
self.view=分页CrollView;
对于(int i=0;i<6;i++)
{
UIView*view=[[UIView alloc]init];
view.backgroundColor=[UIColor blueColor];
CGRect bounds=pagingScrollView.bounds;
CGRect pageFrame=边界;
pageFrame.size.width-=(2*填充);
pageFrame.origin.x=(bounds.size.width*i)+填充;
view.frame=pageFrame;
[pagingScrollView添加子视图:视图];
}
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
[[UIApplication sharedApplication]setStatusBarHidden:是
带动画:UIStatusBarAnimationSlide];
}
-(无效)视图卸载
{
[超级视频下载];
//释放主视图的所有保留子视图。
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回(interfaceOrientation!=UIInterfaceOrientation肖像向上向下);
}
@结束
我能做什么
pageFrame.origin.x = (bounds.size.width * i) + PADDING;
将此部分更改为
pageFrame.origin.x = (bounds.size.width + PADDING) * i;
谢谢你的回答!不幸的是,这只适用于六个视图中的第一个。基本上,我只需要知道如何使用iOS5SDK设置负原点(比如x=-10,y=0)来归档我的目标。有人知道怎么做吗?因为你制作了6页宽的scrollview(pagingScrollView.bounds.size.width*6),我不明白。scrollview的内容大小必须与其中所有页面的总大小相同。内容大小定义了滚动范围。那么这有什么错呢?当我使用一个有六个视图的UIScrollView,并且每个视图之间没有间隙时,它工作得很好。但我想让这些观点之间有差距。基本上,我希望在全屏模式下与iPhone照片应用程序相同。图像之间的间隙仅在从一个图像滚动/切换到下一个图像时出现。不幸的是,我不知道如何存档。成功地使用了这种方法。嗨,你找到解决方案了吗?