gpt4 book ai didi

iphone - 无法更改 UIImageView 中的图像

转载 作者:行者123 更新时间:2023-12-03 21:07:46 24 4
gpt4 key购买 nike

我有一个 ImageView ,每次方向改变时我都试图改变 ImageView 的图像,但图像没有改变任何人都可以帮助我

- (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;

}

最佳答案

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
NSLog(@"interfaceOrientation");
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight,UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown);
// take out the ones you DON'T want to be available
}

// if you want to change things based on orientation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration
{
switch (interfaceOrientation)
{
case UIInterfaceOrientationPortrait:
{
//changes for Portait
NSLog(@"Portait");
[imgView setFrame:CGRectMake(0,0,768,1024)];
[imgView setImage:[UIImage imageNamed:@"1.jpg"]];
}
break;

case UIInterfaceOrientationPortraitUpsideDown:
{
//changes for PortaitUpsideDown
NSLog(@"PortaitUpsideDown");
[imgView setFrame:CGRectMake(0,0,768,1024)];
[imgView setImage:[UIImage imageNamed:@"1.jpg"]];
}
break;


case UIInterfaceOrientationLandscapeRight:
{
//changes for LandscapeRight
NSLog(@"LandscapeRight");
[imgView setFrame:CGRectMake(0,0,1024,768)];
[imgView setImage:[UIImage imageNamed:@"2.jpg"]];

}
break;

case UIInterfaceOrientationLandscapeLeft:
{
//changes for LandscapeRight
NSLog(@"LandscapeRight");
[imgView setFrame:CGRectMake(0,0,1024,768)];
[imgView setImage:[UIImage imageNamed:@"2.jpg"]];
}
break;
}
}

关于iphone - 无法更改 UIImageView 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5595664/

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