gpt4 book ai didi

iphone - 保存和加载一个 UIScrollView 位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:24:51 33 4
gpt4 key购买 nike

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

另外,作为附带的事情...加载 UIScrollView 时我无法使用我的手势识别或 UIAlertView?有谁知道为什么吗?

这是我的代码....提前致谢:)

- layerControl:(NSInteger)index
{
UIScrollView *scroll = [[UIScrollView alloc] 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 < viewCount; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
[filterViewOverlay setImage:[filterManager objectAtIndex:i]];
[scroll addSubview:filterViewOverlay];
[filterViewOverlay release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
[self.view addSubview:scroll];
[scroll release];

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)
{
[[UIScrollView alloc] 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 < viewCount; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
[filterViewOverlay setImage:[filterManager objectAtIndex:i]];
[scroll addSubview:filterViewOverlay];
//[filterViewOverlay release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
[self.view addSubview:scroll];
[scroll autorelease]; */


}
}



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

[self layerControl:[filterController selectedSegmentIndex]];
}

- (UIImage*)saveImages
{

UIImage *image = [UIImage imageNamed:@"UrbanPhoto##1"];

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;

}

最佳答案

尝试在用户操作之前保存 UIScrollView.contentOffset 的值,然后在操作完成后恢复该值。

关于iphone - 保存和加载一个 UIScrollView 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8205740/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com