ページングを有効にして、水平UIScrollViewを作成しました。これにより、特定のビューを「スワイプ」することができます。私が持っている問題は、スクロールビューが左に配置されていることです。私は特定のビューを左にスクロールする(読む:スワイプ)しかできません。私はまた、それを右にスワイプさせたいので、両側。私はそれがUIScrollViewの中心にある問題だと思う。私はたくさんのことを試みましたが、すべてうまくいかなかったのです。UIScrollView中央から左右にページング
ここで(vertScrollが水平scrollViewである)私のコードです:イラスト
- (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.
}
は、ということでしたしかし、 "特定のビュー"は、現在、scrollViewの左側(したがって1ページ目)に配置されています。私はそれをscrollViewの中央に置くことができますか? – user2578311
フレームが正しく設定されていることを確認してください。ページ1の場合、フレームは次のようになります。CGRectMake(0,0、width、height) CGRectMake(幅* 2,0、幅、高さ)になります。 –
これも同様でしたが、scrollViewに残っています(ページ1のように)。 – user2578311