【发布时间】:2016-04-29 14:53:08
【问题描述】:
我做了一个水平的 UIScrollView,启用了分页。这使我可以“滑动”某个视图。我遇到的问题是滚动视图位于左侧。我只能向左滚动(阅读:滑动)我的特定视图。我也想让它向右滑动,所以两边。我认为这是将 UIScrollView 居中的问题。我尝试了很多东西,但都没有成功。
这是我的代码(vertScroll 是水平滚动视图):
- (void)viewDidLoad {
[super viewDidLoad];
vertScroll.contentSize = CGSizeMake(3*375, 232);
vertScroll.frame = CGRectMake(0, 0, 375, 232);
vertScroll.pagingEnabled = YES;
vertScroll.scrollEnabled = YES;
vertScroll.showsHorizontalScrollIndicator = YES;
vertScroll.contentOffset = CGPointMake(375, 0);
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:255.0 green:125.0 blue:71.0 alpha:1.0]];
self.navigationController.navigationBar.topItem.title = @"blabla";
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor whiteColor],
NSFontAttributeName:[UIFont fontWithName:@"StoneSansBold" size:21]}];
self.scrollView.showsVerticalScrollIndicator=YES;
self.scrollView.scrollEnabled=YES;
self.scrollView.userInteractionEnabled=YES;
self.scrollView.contentSize = CGSizeMake(320, 800);
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
// add effect to an effect view
self.effectView = [[UIVisualEffectView alloc]initWithEffect:blur];
self.effectView.alpha = 0.9;
self.effectView.frame = CGRectMake(self.coverImage.frame.origin.x, self.coverImage.frame.origin.y+108, self.coverImage.frame.size.width, 34);
// add the effect view to the image view
[self.coverImage addSubview:self.effectView];
[self.cellView addSubview:self.seismo];
self.seismo = [[UIImageView alloc]initWithFrame:CGRectMake(2, self.coverImage.frame.size.height/2, 40, 40)];
self.seismo.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"tmp-0.gif"],
[UIImage imageNamed:@"tmp-1.gif"],
[UIImage imageNamed:@"tmp-2.gif"],
[UIImage imageNamed:@"tmp-3.gif"],[UIImage imageNamed:@"tmp-4.gif"], nil];
self.seismo.animationDuration = 1.0f;
self.seismo.animationRepeatCount = 0;
[self.seismo startAnimating];
[self.cellView addSubview:self.seismo];
self.seismo.alpha = 0.0;
[self.cellView setFrame:CGRectMake(375, 0, 375, 232)];
// Do any additional setup after loading the view, typically from a nib.
}
【问题讨论】:
标签: ios objective-c uiscrollview