- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我使用 UICollectionView
水平滚动方向创建 PhotoViewer,pagingEnable = true。我创建的 UICollectionViewCell 包含 UIScrollView 以缩放 UIImage。
但是第一个创建 UICollectionViewCell zoomScale
工作,UICollectionCell 重用 zoomScale
不工作。
我的代码:
@interface ImageCell : UICollectionViewCell
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) IBOutlet UIScrollView *scrollView;
@property (nonatomic, strong) NSString *stringURL;
@property (nonatomic, strong) UIImage *img;
- (void)resize;
@end
@interface ImageCell()<UIScrollViewDelegate>
@end
@implementation ImageCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)resize {
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:[NSURL URLWithString:self.stringURL]
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize)
{
// progression tracking code
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
if (image) {
if(self.imgView == nil) {
self.imgView = [[UIImageView alloc] initWithFrame:self.frame];
[self.scrollView addSubview:self.imgView];
}
NSLog(@"%@", NSStringFromCGSize(image.size));
self.img = image;
self.imgView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
self.imgView.image = image;
self.scrollView.contentSize = image.size;
CGRect scrollViewFrame = self.scrollView.frame;
CGFloat scaleWidth = scrollViewFrame.size.width / image.size.width;
CGFloat scaleHeight = scrollViewFrame.size.height / image.size.height;
CGFloat minScale = MIN(scaleWidth, scaleHeight);
self.scrollView.minimumZoomScale = minScale;
self.scrollView.maximumZoomScale = 1;
[self.scrollView setZoomScale:minScale];
[self centerScrollViewContents];
}
}];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imgView;
}
[self.scrollView setZoomScale:minScale];
在创建单元格时工作,当单元格重用不起作用时
最佳答案
这一行来自UIScrollView class reference
The UIScrollView class can have a delegate that must adopt the UIScrollViewDelegate protocol. For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:
所以你还应该实现方法 scrollViewDidEndZooming:withView:atScale:
关于ios - Zoomscale UIScrollView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24117027/
我有一个使用 MapKit 的应用程序。 我在调整 map 大小后计算当前缩放比例。 通过定义(来自MKGeometry.h 文件) MKZoomScale provides a conversion
我有一个UIScrollView中的UIImageView。我使用以下代码将图像加载到UIImageView的CALayer中: UIImage *image = [UIImage imageName
我使用 UICollectionView 水平滚动方向创建 PhotoViewer,pagingEnable = true。我创建的 UICollectionViewCell 包含 UIScrollV
下面的代码在我第一次从相机胶卷中选择图像时按预期运行。图像被缩小以适应 scrollView。但是当我再次运行它以重新选择图像并再次选择相同的图像时,它会缩放到 1.0 比例。无法弄清楚我需要重置什么
我刚刚创建了一个动画来放大或缩小 UIScrollView,但我的问题是 ZoomScale 没有更新。例如,我使用创建的动画缩小 UIScrollView 内的 UIView,但是当我使用展开手势放
我的问题是我想检测 UIWebView 的缩放比例,我尝试搜索它但没有得到正确的答案。感谢任何帮助...... 最佳答案 虽然 UIWebView 没有 zoomScale 属性,但 UIScroll
随着 ScrollView ZoomScale 的减小或增大,ScrollView contentOffset.X 和 contentOffset.Y 的最大值分别减小或增大。我们可以通过编程方式推断
当 UIScrollView 放大时,我遇到了一个奇怪的问题。 我们在 iPad 上的 UIScrollView 中显示用户创建的表单,因此字段的大小可以不同。定位似乎可以很好地处理向上移动字段(通过
如果 zoomScale == oldScale,我正在尝试将 newScale 分配给 UIScrollView 的 zoomScale,并且分配 zoomScale = newScale 不起作用
现在我有一个位于 UIScrollView 之外的 View 。由于多种原因,它不能简单地位于 ScrollView 内。所以现在我正在做的是,随着 UIScrollView 的缩放/平移,我更新了我
我有一个自定义的 UIViewController,我在上面添加了一个 UIImageView(在 StoryBoard 上),然后将 UIImageView 嵌入到 UIScrollView 中。我
我有一个扩展的 UIScrollView,它直接取自 Apple 文档示例项目“ZoomingPDFViewer” 如果你得到这个项目,你会注意到它的 UIScrollView 扩展类“PDFScro
我需要在 UIScrollView 上将 zoomScale 设置回 1,但我需要它是动画的。我以为我可以为此使用 CABasicAnimation,但 NSValue 似乎没有“valueForFl
执行摘要:有时 UIScrollView 会对 contentOffset 的值进行不必要的更改,从而导致应用在正在查看的文档中显示错误的位置。不需要的更改与 ScrollView 的 zoomSca
iOS 应用程序相对较新,而且速度很快,所以我对如何进行有点迷茫。 基本上,我有一个 UIImageView,并且我可以捏合来缩放/滚动,因为我的 UIImageView 在 UIScrollView
我的 UIScrollView 在使用 zoomToRect 时没有设置它的 contentOffset。 我有一个 UIScrollView,里面有一个 UIImageView。到目前为止,滚动和缩
在 ScrollView 的委托(delegate)方法 viewForZoomingInScrollView: 中,我做了看似无辜的事情: //scrollView是传递给该方法的参数 float
我写了一些代码来保存 WKWebView 的 ScrollView 的 contentOffset 和 zoomScale,因此它们可以在 webView 加载后恢复。我发现设置这些 scrollVi
我是一名优秀的程序员,十分优秀!