sync scrollview in parallel way

来源:互联网 发布:洛阳理工学院网络教育 编辑:程序博客网 时间:2024/05/17 08:33

Check out the functions

  • -setContentOffset:animated:
  • -contentOffset
  • -zoomScale
  • -setZoomScale:animated:
  • -zoomToRect:animated:

You can link this together in the delegate method -scrollViewDidScroll:, which is constantly called while the user is scrolling. ...



thank you, works really great! - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if(scrollView==v1) { v2.contentOffset = v1.contentOffset; } else if(....... 

这种方法,除非就是找到了怎么区别代码的移动还是userdragger, 否则很容易导致问题啊,难道说由于放在了一个

delegate反而好了,因为只会进来一次??可以考虑哦:)


还有一个超级复杂的例子,用了很多notification


- (IBAction)toggleSynchronizing:(id)sender

{

if (synchronized) {å

NSView* synchronizedContentView = [synchronizedScrollView contentView];

[[NSNotificationCenter defaultCenter] removeObserver:self

name:NSViewBoundsDidChangeNotification

  object:synchronizedContentView];

    }else {

NSView *synchronizedContentView=[synchronizedScrollView contentView];

[synchronizedContentView setPostsBoundsChangedNotifications:YES];

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(synchronizedViewContentBoundsDidChange:)

name:NSViewBoundsDidChangeNotification

   object:synchronizedContentView];

}

synchronized=!synchronized;

}


原创粉丝点击