【问题标题】:Scroll VIiew Class iOS滚动视图类 iOS
【发布时间】:2012-03-30 00:44:16
【问题描述】:

我的程序甚至没有进入scrollViewDidScroll 方法。我不知道为什么。我的视图确实加载看起来像这样:

- (void)viewDidLoad
{
   [super viewDidLoad];

   // Set the size of the content to be displayed
   self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.size.width * ScrollViewControllerNumberOfPages, self.scrollView.bounds.size.height);

   // Turn on paging in the scroll view (can also be done in Interface Builder)
   self.scrollView.pagingEnabled = YES;

   NSLog(@"CurrentPage ViewDidLoad%@",self.pageControl.currentPage);
   switch (self.pageControl.currentPage)
   {
       case 1:
           [self.minkyImageView setImage:[UIImage imageNamed:@"monkey_1.png"]]; 
           NSLog(@"case1");
           break;
       case 2:
           [self.minkyImageView setImage:[UIImage imageNamed:@"Shape1.png"]];
            NSLog(@"case2");
           break;
       default:
           break;
   }     
}

我还像这样在我的界面上实现了scrollviewDelegate。我不明白我做错了什么。它甚至没有进入名为scrollViewDidScroll 的方法。

@interface MinkyScreenSwapViewController: UIViewController <UIScrollViewDelegate>

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat contentWidth = scrollView.bounds.size.width;
CGFloat halfContentWidth = contentWidth / 2;
NSInteger currentPage = (scrollView.contentOffset.x + halfContentWidth) / contentWidth;
self.pageControl.currentPage = currentPage;
NSLog(@"CurrentPage");
}

【问题讨论】:

    标签: ios iphone objective-c ios4 uiscrollview


    【解决方案1】:

    试用:

    self.scrollView.delegate = self;
    

    希望这会有所帮助。

    【讨论】:

    • 是的,我做到了,现在进入方法,谢谢。但是对于 self.pageControl.currentPage 它总是打印 null .. 上面编辑的代码。我不确定这是为什么。
    【解决方案2】:

    试试这些代码

    scrollView.delegate = self;
    
    scrollView.userInteractionEnabled=YES;
    

    如果你在图像视图上添加滚动视图,你必须明确设置

    imageView.userInteractionEnabled=YES;
    

    为了更方便设置

    [[scrollView superView] setUserInteractionEnabled:YES];
    

    这些将使您的 scrollView 委托方法处于活动状态。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-25
      相关资源
      最近更新 更多