我有一个标题/品牌形象,这改变了iPad和iPhone,但不会改变图片时,从肖像到景观,这是真正重要的是,它做到了。
我有一个HeaderView类,由tableViewControllers这样调用:
self.tableView.tableHeaderView = [[HeaderView alloc] initWithText:@""];它包含一个UIImageView:
@interface HeaderView : UIImageView{
}
- (id)initWithText:(NSString*)text;
- (void)setText:(NSString*)text;
@end对于M文件,我们发现哪里没有得到我想要的结果:
#import "HeaderView.h"
#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
@interface HeaderView()
{
UILabel*label;
}
@end
@implementation HeaderView
- (id)initWithText:(NSString*)text
{
UIImage* img = [UIImage imageNamed:@"WashU.png"];
UIImage* iPhonePortrait = [UIImage imageNamed:@"WashU2.png"];
UIImage* image = [[UIImage alloc] init];
UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
//different header image for different devices...
if(IDIOM==IPAD){
image = img;
}
else{
if(UIInterfaceOrientationIsPortrait(interfaceOrientation)){
image = iPhonePortrait;
}
else if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
iPhonePortrait = nil;
image = img;
}
}
[headerImageView setImage:image];
if (self = [super initWithImage:image]){
}
return self;
}我还添加了以下方法:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}我肯定这是个经典的问题,但我有点困惑。同时,如果我移除
[headerImageView setImage:image]; ,以及
[self addSubview:headerImageView];,图像仍然会显示,这意味着
if (self = [super initWithImage:image])正在做所有的显示工作。
发布于 2013-03-01 17:21:18
didRotateFromInterfaceOrientation在旋转后发送到视图控制器,您可以实现这一点来更改图像。
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
...change your image here
}发布于 2013-03-01 17:44:19
实际上,您并没有将图像分配给imageView。添加:
headerImageView.image = image;在“图像”之后的某个地方已经设置好了(基于iPad vs iPhone和肖像与景观)。
发布于 2013-03-01 17:55:23
作为您的代码,您不需要分配(UIImage*)图像属性,因为您将分配(UIImage*)img或(UIImage*)iPhonePortrait。并应将图像分配给headerImageView.image。
[headerImageView setImage:image];https://stackoverflow.com/questions/15163149
复制相似问题