0

私は3つのページを持っています。これらはすべてYouTubeビデオ(Webビュー)を含み、これらのWebビューはスクロールビュー内にあります。私はこれを行うためにチュートリアルを使用しました。そのチュートリアルでは、どちらかの方向にスワイプするたびに次のページで停止します(iosホーム画面のように)が、私のものは動き続け、スワイプモーションの長さに応じて停止します。

これが.mの私のコードです:

#import "FeaturedVideosViewController.h"

@interface FeaturedVideosViewController ()

@end

@implementation FeaturedVideosViewController

@synthesize scrollView, pageControl;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}



- (void)viewDidLoad {
[super viewDidLoad];

pageControlBeingUsed = NO;
{
    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * 3;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;

    UIView *subview = [[UIView alloc] initWithFrame:frame];
        [self.scrollView addSubview:subview];

}

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 3, self.scrollView.frame.size.height);

self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = 3;
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/embed/wYkIhYtN7yA"]]];
[WebView2 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/embed/4O7kTOTg1UE"]]];
[WebView3 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/embed/vmUW41m93oY"]]];
}

- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (!pageControlBeingUsed) {
    // Switch the indicator when more than 50% of the previous/next page is visible
    CGFloat pageWidth = self.scrollView.frame.size.width;
    int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    self.pageControl.currentPage = page;
}
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
}

- (IBAction)changePage {
// Update the scroll view to the appropriate page
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];

// Keep track of when scrolls happen in response to the page control
// value changing. If we don't do this, a noticeable "flashing" occurs
// as the the scroll delegate will temporarily switch back the page
// number.
pageControlBeingUsed = YES;
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.scrollView = nil;
self.pageControl = nil;
}




@end

たとえば、iOSのホーム画面のように各ページで停止するにはどうすればよいですか?

4

2 に答える 2

2

UIScrollViewのpagingEnabledをYESに設定しましたか。

- (void)viewDidLoad {
    [super viewDidLoad];
    // EXISTING CODE
    self.scrollView.pagingEnabled = YES;
  }
于 2013-03-24T18:03:58.747 に答える
0

UIScrollViewをクリックし、右側(属性インスペクター)で[ページングを有効にする]にチェックマークを付けます。またはプログラムで設定することもできます

scrollView.pagingEnabled = yes;

それでおしまい...

于 2015-08-13T06:25:53.580 に答える