English 中文(简体)
缩略语 回到国际会计师联合会的意见后,观点的起源变化
原标题:UIScrollView s origin changes after popping back to the UIViewController

页: 1 观点,包括各种次目。 其中一个次调查是<条码>tButton,然后排入另一个场面<条码>。 当我回过来时(见 UIViewController,偏离导航控制器组),我发现,尽管<代码>contentsize和contentoffset,但浏览器的原产地发生了一些变化。 似乎正确。

同样令人感兴趣的是,这 app有一条禁忌,当我放弃并赞同这一观点时,滚动观点被正确地击退(0、0)。

这一进程基本上没有守则,因为它在故事板上占了很大的比例。 由于我对使用故事片很新,我觉得我错了,尽管我不知道什么。 对可能是什么想法? 也许会把问题或制约因素化为乌有?

最佳回答

Actually, I put that line of code in viewDidDisappear, and so that it remembers the offset when the view reappears, I added this line before it

 self.contentOffset = self.scrollView.contentOffset;

以及

 - (void)viewDidLayoutSubviews { 
       self.scrollView.contentOffset = self.contentOffset; 
 }
问题回答

在OS 7/8/9 简单的<代码>上,自动通过AdjustsScrollViewInsets = NO;解决了我的案件。

鉴于观点控制者WillAppear,你pop回:

 self.scrollView.contentOffset = CGPointMake(0, 0);

www.un.org/Depts/DGACM/index_spanish.htm Edit: 在增加Peter代码时,取得最佳结果:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.scrollView.contentOffset = CGPointMake(0, 0);
}

- (void)viewWillDisappear:(BOOL)animated {  
    self.recentContentOffset = self.scrollView.contentOffset;
    [super viewWillDisappear:animated];
}

以及

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.scrollView.contentOffset = CGPointMake(0, self.recentContentOffset.y);
}

You return to the original scroll position, have no visual side-effect 以及 the scroll view itself is correctly positioned in its superview (which was a problem) after coming back.

i 在驳回观点后,存在类似的问题。 主计长将我的表态中的内容转换为(0,64)。

我的解决办法是一小 we,一是尝试了所有其他答案,但却没有成功,唯一的问题就是把表态放在控制树上。

这是父母的首例控制。 类似观点:

“ati”/

我在《图像评论》发表后提出书面意见。

https://i.stack.imgur.com/Z8ujQ.jpg” alt=" subsequently>

it seems that putting the table view in the first position was causing the trouble, and moving the table view to another position fixed the problem.

P.D. I m not using autoLayout neither storyboards

希望能帮助人们!

I m使用收集意见,我也存在同样的问题。 对SOS 11:在规模检查员中,有“连续”。 规定“无”。 这解决了我的问题。 我希望这能帮助某人。

目标C:

if (@available(iOS 11, *)) {
   [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}

Swift:

if #available(iOS 11, *) {
UIScrollView.appearance().contentInsetAdjustmentBehavior = .never
}

在OS 11中,我面临一个类似的问题,即当我收到一位观察控制员后回来时,前一位观察控制员的表象被用来自动调整其内容,从而导致表形内容从上突然跳出。 下面的解决办法是为我11世纪的工作。

在故事板上,选择了表象,然后到Attributes监察员和罗望和估算田的“Automatic”检查。 内容从“外交”改为“无”。

[“Table]

不幸的是,Peter和MacMark的建议对我没有作用(Xcode 5 w/ autolayout)。 解决办法是进入故事板,选择观察控制器和<密码>。 Reset to Proposaled Constraints in Viewller.

enter image description here

I posted a question recently about a similar issue but in a different context: Frame doesn t reflect auto layout constraints after dismissing modal view controller

就我的情况而言,滚动观点中的习惯集装箱观点的起源是流离失所的,而不是滚动观点的起源。 关于汽车布局,海关集装箱的视线由滚动观点的四边组成。

The container view is created and configured programmatically rather than in IB. Although the constraints of the container view are unchanged, the container view s origin is displaced after dismissing a modal view controller. This disconnect between constraints and frames is inexplicable.

更令人瞩目是,流离失所问题在我撤除和重新出现所有相关制约因素之后依然存在。

我也提出了类似的解决办法:除了现有内容的价值外,将内容打上“零”,让系统放弃你们的意见,然后恢复内容(即:内容跳舞)。

然而,在我的案件中,我不得不采取更多步骤解决这一问题。 我的滚动看法是,一种从零敲碎打方法(用旧的WWDC录像播放)中得出的分辨率。 改变滚动观点的内容,通过UIScrollViewDelegate scrollViewDidScroll:方法,抵消了断裂的方法。 我必须打上旗帜,在我做的是装饰舞的时候,否则,服饰会倒。

我希望,在我升至7时,我可以删除内容跳舞守则。

Continued Issue when following the current answers:

第二次试图开放所提出的观点控制人,而没有离开提出看法的控制者,这个问题依然存在。 正因为如此,我张贴了导致我解决办法的步骤

  1. 因此,Ireset 意见书在书记板上受到制约,因此,他们肯定会提出主意。

  2. <stored, private, the contentOffset of the Collection view prior to the Formatly presented view controller shoe:

    (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    
        self.contentOffset = self.collectionView.contentOffset;
        self.collectionView.contentOffset = CGPointZero;
    }
    
    - (void)viewDidLayoutSubviews {
         [super viewDidLayoutSubviews];
         self.collectionView.contentOffset = self.contentOffset;
    }
    

最近,我遇到了这一难题,可以使用这些法典解决:

// fix ios 6 bug begin
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
        isRecoredforios6 = YES;
        recordedOffsetforios6 = self.tableView.contentOffset;
        recordedSizeforios6 = self.tableView.contentSize;
    }
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    if (isRecoredforios6) {
        isRecoredforios6 = NO;
        self.tableView.contentSize = recordedSizeforios6;
        self.tableView.contentOffset = recordedOffsetforios6;
    }
}
// fix ios 6 bug end

感谢Peter Jacobs!

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
        _isRecoredforios6 = YES;
        _recordedOffsetforios6 = _scrollView.contentOffset;
        _recordedSizeforios6 = _scrollView.contentSize;
        _scrollView.contentOffset = CGPointZero;
    }

}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    if (_isRecoredforios6) {
        _isRecoredforios6 = NO;
        _scrollView.contentSize = _recordedSizeforios6;
        _scrollView.contentOffset = _recordedOffsetforios6;
    }
}

I have fixed this ios6 bug , can be solved using these codes. I solved bug occurred in Scrollview. Thank above all my friends!

在尝试大量事情之后:

  • Set automaticallyAdjustsScrollViewInsets to false to see if the problem was with the navigation bar.
  • Playing with fixed cell heights...
  • Caching the cell heights...
  • Keeping a property with the table view offset, caching it and setting it on viewWillAppear...
  • etc.

我对问题进行了探讨,即:<代码> 估计数dRowHels/code>值,该数值定为50px,当时应为~150px。 更新价值确定了问题,现在,表认为保持同样的平衡。

你们是否试图根据奥帕克律师协会的选择来检查扩大的边缘? 可见诸于你的控制者在故事片板内的检查人员。

当时我用XCode 9 OS 11 trick。

“在此处的影像描述”/</a

以上没有一人为我工作,我设法用自己的习俗Push/Pull消化,并像一个药店一样工作。

第一,增加执行这一类措施 缓冲情景

class PushAnimator: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
    return 0.5
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

    // get reference to our fromView, toView and the container view that we should perform the transition in
    let container = transitionContext.containerView
    let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from)!
    let toView = transitionContext.view(forKey: UITransitionContextViewKey.to)!

    // start the toView to the right of the screen
    var frame = toView.frame
    frame.origin.x = container.frame.width
    toView.frame = frame

    // add the both views to our view controller
    container.addSubview(toView)
    container.addSubview(fromView)

    // get the duration of the animation
    let duration = self.transitionDuration(using: transitionContext)

    // perform the animation!
    UIView.animate(withDuration: duration, animations: {

        var frame = fromView.frame
        frame.origin.x = -container.frame.width
        fromView.frame = frame

        toView.frame = container.bounds

    }, completion: { _ in
        // tell our transitionContext object that we ve finished animating
        transitionContext.completeTransition(true)

    })
}
}

之后,添加这一类,以实施流行情景

import Foundation
import UIKit

class PopAnimator: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
    return 0.5
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    // get reference to our fromView, toView and the container view that we should perform the transition in
    let container = transitionContext.containerView
    let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from)!
    let toView = transitionContext.view(forKey: UITransitionContextViewKey.to)!

    // set up from 2D transforms that we ll use in the animation
    let offScreenRight = CGAffineTransform(translationX: container.frame.width, y: 0)

    // start the toView to the right of the screen
    var frame = toView.frame
    frame.origin.x = -container.frame.width
    toView.frame = frame

    // add the both views to our view controller
    container.addSubview(toView)
    container.addSubview(fromView)

    // get the duration of the animation
    let duration = self.transitionDuration(using: transitionContext)

    // perform the animation!
    UIView.animate(withDuration: duration, animations: {

        fromView.transform = offScreenRight
        toView.frame = container.bounds

    }, completion: { _ in
        // tell our transitionContext object that we ve finished animating
        transitionContext.completeTransition(true)

    })
}
}

然后,在你看来,将这条线加起来,以改变违约的导航主计长代表。

self.navigationController?.delegate = self

参看魔法:

我利用了在任何地方张贴的不同解决方案,并带着这一次子:

// Keeps track of the recent content offset to be able to restore the
// scroll position when a modal viewcontroller is dismissed
class ScrollViewWithPersistentScrollPosition: UIScrollView {

    // The recent content offset for restoration.
    private var recentContentOffset: CGPoint = CGPoint(x: 0, y: 0)

    override func willMove(toWindow newWindow: UIWindow?) {
        if newWindow != nil {
            // save the scroll offset.
            self.recentContentOffset = self.contentOffset
        }
        super.willMove(toWindow: newWindow)
    }

    override func didMoveToWindow() {
        if self.window != nil {
            // restore the offset.
            DispatchQueue.main.async(execute: {
                // restore it
                self.contentOffset = self.recentContentOffset
            })
        }
        super.didMoveToWindow()
    }
 }

测试了11.2 /Xcode 9.2。

Just in case none of the above helped, I had this issue as well as the issue for me was that i had the following code..

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    tableView.reloadData()
}

在评论这一重载数据线时,我将这个问题定下来。 我确实不需要这条线,因此我甚至不敢肯定为什么会增加它!

Hopefully this solution helps someone else.

检查你的剪辑内容大小,这将成为根本原因





相关问题
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, ...

热门标签