ios - ScrollView 类 iOS

标签 ios iphone objective-c ios4 uiscrollview

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

- (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");
}

最佳答案

试用:

self.scrollView.delegate = self;

希望这可以帮助。

关于ios - ScrollView 类 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9687029/

相关文章:

ios - 如何从 ABAddressBookRegisterExternalChangeCallback 获取更新的联系人列表?

ios - PerformSelectorInBackground 无法正常工作

ios - 使用 Swift 3 和 Realm 同步 Apple Watch 和 iPhone

ios - 从 Google Cardboard 升级到 Google VR 的项目在 Unity 中运行,但在构建 iOS(XCode 或 Unity Cloud Build)时失败

javascript - 通过if条件防止双击事件

ios - CGAffineTrasformRotation 也会旋转坐标系统

iphone - 使用 IB 在 UIButton 上居中多行文本

ios - 单击 UIBar 按钮时删除 TabBar Controller

objective-c - 为什么有些对象在 objective-c 中使用前不需要初始化?

objective-c - 没有协议(protocol)的 iOS 委托(delegate)?