菜鸟教程小白 发表于 2022-12-11 20:33:13

iphone - 保存并加载 UIScrollView 位置


                                            <p><p>我正在创建一个应用程序,该应用程序使用滚动图像的 UIScrollView 和加载新 View 并允许新图像层(有点像 Photoshop 分层)的分段控件 - 出于某种原因,当我单击该层时,它记住该位置但创建一个新图层.... 我怎样才能阻止这种情况发生,所以一旦选择了图层并选择了图像,当用户返回时,它会转到最后加载的位置?</p>

<p>另外,作为附带的事情...当 UIScrollView 加载时,我不能使用我的手势识别或 UIAlertView?有谁知道为什么?</p>

<p>这是我的代码....提前致谢:)</p>

<pre><code>- layerControl:(NSInteger)index
{
UIScrollView *scroll = [ initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger viewCount = 15;
for (int i = 0; i &lt; viewCount; i++) {
    CGFloat yOrigin = i * self.view.frame.size.width;
    UIImageView *filterViewOverlay = [ initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
    ];
    ;
    ;
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
;
;

switch (index)
{
    case 0: scroll = self.scroll1;
    case 1: scroll = self.scroll2;
    case 2: scroll = self.scroll3;
    case 4: scroll = self.scroll4;
    case 5: scroll = self.scroll5;

}

/* if (scroll == nil)
{
    [ initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scroll.pagingEnabled = YES;
    NSInteger viewCount = 15;
    for (int i = 0; i &lt; viewCount; i++) {
      CGFloat yOrigin = i * self.view.frame.size.width;
      UIImageView *filterViewOverlay = [ initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
      ];
      ;
      //;
    }
    scroll.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
    ;
    ; */


}
}



//Method to add a filter to the page
- (void)addFilter:(id)sender
{
    UISegmentedControl *filterController = (UISegmentedControl *)sender;

];
}

- (UIImage*)saveImages
{

UIImage *image = ;

UIGraphicsBeginImageContext(self.view.bounds.size);
;
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;

}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>尝试在用户操作之前保存 <code>UIScrollView.contentOffset</code> 的值,然后在操作完成后恢复该值。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 保存并加载 UIScrollView 位置,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/8205740/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/8205740/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 保存并加载 UIScrollView 位置