为什么背景图片不会出现在我的滚动视图中?
-(void) loadView {
CGRect screenRect = [[UIScreen mainScreen]bounds];
UIView *menuView = [[UIView alloc]initWithFrame:screenRect];
self.view = menuView;
UIImage *backgroundImage = [UIImage imageNamed:@"Spacemenu.jpg"];
UIScrollView *menuScrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
menuScrollView.backgroundColor = [UIColor clearColor];
menuScrollView.contentSize = backgroundImage.size;
UIImageView *imageView = [[UIImageView alloc]initWithImage:backgroundImage];
[self.view addSubview:menuScrollView];
[self.view insertSubview:imageView belowSubview:menuScrollView];
}
我想制作一个滚动视图,它在背景中水平滚动到一个长矩形图像。请帮忙
答案 0 :(得分:0)
menuScrollView.contentSize = backgroundImage.size;
在contentSize
viewDidAppear
如果您想使用滚动视图平移图片,则必须将imageView
添加到scrollView
,而不是self.view.
答案 1 :(得分:0)
这是我用来将一个背景图片放在tableView下面的代码,应该使用scrollview(tableview继承自scrollview)
UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];
backgroundImage.frame = self.view.frame;
[self.view insertSubview:backgroundImage atIndex:0];
self.tableView.backgroundView = nil;
self.tableView.backgroundColor = nil;
通过改编:
-(void)viewDidLoad {
[super viewDidLoad];
...
//create your scrollView
menuScrollView.backgroundView = nil;
menuScrollView.backgroundColor = nil;
UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];
backgroundImage.frame = self.view.frame;
[self.view insertSubview:backgroundImage atIndex:0];
}
答案 2 :(得分:0)
尝试将scrollView
添加到self.view
:
[self.view addSubview:menuScrollView]
然后:
[menuScrollView addSubview:imageView]
让我知道会发生什么。 ;)