Iphone 这是UIScrollView中的缩放错误吗?
在符合UIApplicationDelegate和UIScrollViewDelegate的类中,我在中执行了以下操作:Iphone 这是UIScrollView中的缩放错误吗?,iphone,uiscrollview,Iphone,Uiscrollview,在符合UIApplicationDelegate和UIScrollViewDelegate的类中,我在中执行了以下操作: - (void)applicationDidFinishLaunching:(UIApplication *)application { // Created an instance of UIScrollView to house a horizontal strip - along the x-axis - of kNumberOfPages UIViews:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Created an instance of UIScrollView to house a horizontal strip - along the x-axis - of kNumberOfPages UIViews:
scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
// Make self the delegate
scrollView.delegate = self;
// Set content size to the cumulative width of all UIViews contained
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
// Zoom range is from a min of the width of the scrollView to a max of 2 * scrollView.contentSize
scrollView.minimumZoomScale = scrollView.frame.size.width / scrollView.contentSize.width;
scrollView.maximumZoomScale = 2 * scrollView.contentSize;
// A subclass of UIView will be the container for the horizontal strip of UIViews
containerView = [[ConstrainedView alloc] initWithFrame:CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height)];
// The only difference betrween ConstrainedView and UIView is this overloaded method that constrains zooming to only the x-axis
- (void)setTransform:(CGAffineTransform)newValue {
// Scale along the y-axis only
CGAffineTransform constrainedTransform = CGAffineTransformScale(CGAffineTransformIdentity, newValue.a, 1.0);
[super setTransform:constrainedTransform];
}
// Fill the container view with UIViews as subviews
CGFloat horizontalOffsetX = 0.0;
for (int i = 1; i <= kNumberOfPages; i++) {
CGRect frame = CGRectMake(horizontalOffsetX, 0.0, scrollView.frame.size.width, scrollView.frame.size.height);
UIView *v = [[[UIView alloc] initWithFrame:frame] autorelease];
// paint the background of each UIView a random color.
v.backgroundColor = [UIColor colorWithRed:randomRed green:randomGreen blue:randomBlue alpha:1.0];
[containerView addSubview:v];
horizontalOffsetX += v.bounds.size.width;
} // for (kNumberOfPages)
// insert the container view as a subview of scrollView
[scrollView addSubview:containerView];
[window addSubview:scrollView];
[window makeKeyAndVisible];
}
-(void)applicationdFinishLaunching:(UIApplication*)应用程序{
//创建了一个UIScrollView实例,以沿x轴放置KNumberOfUI视图的水平条带:
scrollView=[[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
//让自己成为代表
scrollView.delegate=self;
//将内容大小设置为包含的所有UIView的累积宽度
scrollView.contentSize=CGSizeMake(scrollView.frame.size.width*kNumberOfPages,scrollView.frame.size.height);
//缩放范围从scrollView的最小宽度到最大2*scrollView.contentSize
scrollView.minimumZoomScale=scrollView.frame.size.width/scrollView.contentSize.width;
scrollView.maximumZoomScale=2*scrollView.contentSize;
//UIView的子类将是UIView水平条的容器
containerView=[[ConstrainedView alloc]initWithFrame:CGRectMake(0,0,scrollView.contentSize.width,scrollView.contentSize.height)];
//ConstrainedView和UIView之间的唯一区别是此重载方法仅限制缩放到x轴
-(void)setTransform:(CGAffineTransform)newValue{
//仅沿y轴缩放
CGAffineTransform constrainedTransform=CGAffineTransformScale(CGAffineTransformIdentity,newValue.a,1.0);
[超级集合变换:约束变换];
}
//使用UIView作为子视图填充容器视图
CGFloat horizontalOffsetX=0.0;
对于(inti=1;i更新
我的方法似乎确实适用于以下警告。这里似乎有一个边界条件问题
这项工作:
scrollView.minimumZoomScale=(scrollView.frame.size.width/scrollView.contentSize.width)/0.99
这会挂起-崩溃-应用程序:
scrollView.minimumZoomScale=scrollView.frame.size.width/scrollView.contentSize.width
只要scrollView的宽度超过了内容的宽度,不管是否进行了不同的缩放,该应用程序似乎工作正常
我可以很容易地克服这个小限制。酷
干杯
道格更新
我的方法似乎确实适用于以下警告。这里似乎有一个边界条件问题
这项工作:
scrollView.minimumZoomScale=(scrollView.frame.size.width/scrollView.contentSize.width)/0.99
这会挂起-崩溃-应用程序:
scrollView.minimumZoomScale=scrollView.frame.size.width/scrollView.contentSize.width
只要scrollView的宽度超过了内容的宽度,不管是否进行了不同的缩放,该应用程序似乎工作正常
我可以很容易地克服这个小限制。酷
干杯
Doug我注意到这一行scrollView.MaximumZoomSale=2*scrollView.contentSize;
似乎不正确?我认为应该是scrollView.MaximumZoomSale=2;
我注意到这一行scrollView.MaximumZoomSale=2*scrollView.contentSize;
似乎不正确?我认为应该是scrollView.MaximumZoomSale=2;