我有一个UIView
可以滚动但不能缩放的子类。我正在使用自动布局,所以想知道 IOS6 中是否有任何变化。特别是何时实现scrollViewWillBeginZooming
和scrollViewDidEndZooming
方法。我的代码看起来像
- (void)viewDidLoad
{
[super viewDidLoad];
self.ringSet2 = [[RingView alloc] initWithFrame:CGRectMake(0, 0, 800, 800)];
[self.ringSet2 setDefaults];
/// ... more setup for other views but only ringSet2 is scrolled.
self.scrollview1.delegate=self;
self.scrollview1.scrollEnabled=YES;
self.scrollview1.contentSize=self.ringSet2.bounds.size
self.scrollview1.minimumZoomScale=0.2;
self.scrollview1.maximumZoomScale=5.0;
self.ringSet2.userInteractionEnabled=YES;
// ... needed elsewhere so other views can pick up their dimensionts
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
/// ... code for additional views
[self.scrollview1 zoomToRect:CGRectMake(0, 0, 200, 200) animated:YES];
[self.scrollview1 addSubview:self.ringSet2];
}
和
-(UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return self.ringSet2;
}
等等scrollViewWillBeginZooming
。实施只是为了追踪正在发生的事情。有趣的是,
viewForZoomingInScrollView
似乎只被调用一次,因为scrollViewDidEndZooming
比例值略低于 1 但从scrollViewWillBeginZooming
未被调用。定义了属性 ringSet2
@property (strong, nonatomic) IBOutlet RingView *ringSet2;
因为如果视图被定义为弱,则视图不会出现。