无法更改 UIImageView 中的图像
我有一个图像视图,每次方向改变时我都试图改变图像视图的图像,但图像没有改变任何人都可以帮助我吗
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (!mainBackgroundImageView) {
mainBackgroundImageView=[[UIImageView alloc] init];
}
if (interfaceOrientation==UIInterfaceOrientationPortrait || interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
UIImage *tempImage=[UIImage imageNamed:@"dart-login-image.png"];
[mainBackgroundImageView setImage:tempImage];
[tempImage release];
}
else {
[mainBackgroundImageView setImage:[UIImage imageNamed:@"background-and-header-integerated.png"]];
}
return YES;
}
I have an image view and I am trying to change image of imageview everytime the orientation changes but the image is not changing can anybody help me on this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (!mainBackgroundImageView) {
mainBackgroundImageView=[[UIImageView alloc] init];
}
if (interfaceOrientation==UIInterfaceOrientationPortrait || interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
UIImage *tempImage=[UIImage imageNamed:@"dart-login-image.png"];
[mainBackgroundImageView setImage:tempImage];
[tempImage release];
}
else {
[mainBackgroundImageView setImage:[UIImage imageNamed:@"background-and-header-integerated.png"]];
}
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在错误的位置更改了图像,
对于支持的界面旋转,应该只返回 YES 或 NO。
实施:
并更改那里的图像。
另外,如果您使用 imageNamed: 创建 tempImage,则不需要释放它,它已经自动释放了。
You're changing the image in the wrong place,
should only return YES or NO for supported interface rotations.
Implement:
and change the image there.
Also you don't need to release tempImage if your create it with imageNamed:, it's already autoreleased.
有趣的代码...
您在此处创建一个 UIImageView 对象:
没有证据表明它已添加到视图中的任何位置。例如:
此外,您支持所有旋转,因此只需在此处返回 yes
将工作放在这里...
所有这一切都假设您已经将 mainBackgroundImageView 添加到视图中的某个位置,例如 -(void)viewDidLoad 中。
Interesting code...
You create a UIImageView object here:
There's no evidence that this is added to the view anywhere. For example:
Additionally, you're supporting all rotations, so just return yes here
Put the work here...
All of this assumes you've already added mainBackgroundImageView to your view somewhere like in -(void)viewDidLoad.