English 中文(简体)
固定的自动轨道失去精确性?
原标题:setContentOffset loses precision?

我有一份申请,要求将<条码>contentOffset的<条码>(>,View/code>初步确定为一定价值。 我在设定<代码>contentOffset时注意到,该编码将各点移至最接近的分类。 I ve Trial using both setContentOffset and setContentOffset:animated, still receive the same results. 当我试图人工添加<代码>contentOffset时,我没有获得我想要的结果。 任何人都知道这方面的任何进展?

UIScrollView *myScrollViewTemp = [[UIScrollView alloc] initWithFrame: CGRectMake(CropThePhotoViewControllerScrollViewBorderWidth, CropThePhotoViewControllerScrollViewBorderWidth, self.myScrollViewBorderView.frame.size.width - (CropThePhotoViewControllerScrollViewBorderWidth * 2), self.myScrollViewBorderView.frame.size.height - (CropThePhotoViewControllerScrollViewBorderWidth * 2))];
[self setMyScrollView: myScrollViewTemp];
[[self myScrollView] setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self myScrollView] setShowsVerticalScrollIndicator: NO];
[[self myScrollView] setShowsHorizontalScrollIndicator: NO];
[[self myScrollView] setBouncesZoom: YES];
[[self myScrollView] setDecelerationRate: UIScrollViewDecelerationRateFast];
[[self myScrollView] setDelegate:self];
[[self myScrollViewBorderView] addSubview: [self myScrollView]];
[myScrollViewTemp release];

UIImageView *myImageViewTemp = [[UIImageView alloc] initWithImage: self.myImage];
[self setMyImageView: myImageViewTemp];
[[self myScrollView] addSubview:[self myImageView]];
[[self myScrollView] setContentSize: [self.myImage size]];
[[self myScrollView] setMinimumZoomScale: self.previousZoomScale];
[[self myScrollView] setMaximumZoomScale: 10];
[[self myScrollView] setZoomScale: self.previousZoomScale animated:NO];
[[self myScrollView] setContentOffset: self.contentOffset animated:NO];
[myImageViewTemp release];

UPDATE: Updated Code.

最佳回答

这似乎是我方的ug子,而是 Apple果的意图行为,无论是目的还是目的。 为了围绕这一点开展工作,你需要将内容汇编列入国际会计师联合会的观察方法。 显然,你需要在确定整个观点框架之后确定内容。

问题回答

我也同这个问题进行了相当的斗争,但我却指出,你只能把束缚放在滚动观点上,而这种观点确实是一样的,而且实际上与森林渔业总会的价值观有关。

CGPoint newOffset = CGPointMake(3.8, 0);

我们在此获得新的抵消。

[scrollView setContentOffset:newOffset];

其后,现冲抵(4 000美元)。

scrollView.bounds = CGRectMake(newOffset.x, newOffset.y, scrollView.bounds.size.width, scrollView.bounds.size.height);

这给你(3.8、0)

Swift 4:

我宣布了更精确的延长:

extension UIScrollView {
    func setPreciseContentOffset( x:CGFloat? = nil, y:CGFloat? = nil, animated:Bool,completion:@escaping ((Bool) -> Void)) {
        var myX:CGFloat = self.contentOffset.x
        var myY:CGFloat = self.contentOffset.y
        if let x = x {
            myX = x
        }
        if let y = y {
            myY = y
        }
        let point = CGPoint(x:myX,y:myY)
        if animated {
            // calculate duration
            var duration = 0.25 // min duration
            let destCoord =  myX != self.contentOffset.x ? myX : myY
            let diff = fabs ( self.contentOffset.x - destCoord)
            duration += TimeInterval(diff) / 1000
            UIView.animate(withDuration:duration, delay: 0.0, options: [.curveEaseInOut], animations: {
                self.bounds = CGRect(x:point.x,y:point.y,width: self.bounds.size.width,height: self.bounds.size.height)
            }, completion: { (finished: Bool) in
                completion(finished)
            })
        } else {
            self.bounds = CGRect(x:point.x,y:point.y,width: self.bounds.size.width,height: self.bounds.size.height)
            completion(true)
        }
    }
}

Usage:

// supposing you have to scroll manually in horizontal

self.myScrollview.setPreciseContentOffset(x:contentX, animated: true, completion: {[weak self] _ in
        guard let `self` = self else { return }
        // HERE the scroll is ended, pay attention the end scrolling delegates aren t be called  because you set manually self.bounds so HERE implement your scrolling end code
    })

我认为,这是因为,如果内容Offset没有四舍五入,特别是案文,UIScroll意见的任何分述内容就会变得模糊不清。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签