TabBar 应用程序中横向和纵向视图的问题

发布于 2024-08-28 20:35:52 字数 2705 浏览 2 评论 0原文

我有一个 TabBar 应用程序,我希望它是横向和纵向的。问题是,当我转到选项卡 2 从表格中进行选择,然后选择选项卡 1 并旋转设备,然后再次选择选项卡 2 时,内容不知道设备已旋转,并且不会正确显示我的自定义定向内容。我正在尝试编写一个私有方法来告诉视图当前的方向。在 viewDidLoad 中,我假设它是纵向的,但在 shouldAutoRotate 中,我让它在私有方法中查找内容的正确对齐方式。请帮助!这是我的代码:

#import "DetailViewController.h"
#import "ScheduleTableViewController.h"
#import "BrightcoveDemoAppDelegate.h"
#import "Constants.h"

@implementation DetailViewController


@synthesize CurrentLevel, CurrentTitle, tableDataSource,logoName,showDescription,showDescriptionInfo,showTime, showTimeInfo, tableBG;

- (void)layoutSubviews {

 showLogo.frame = CGRectMake(40, 20, 187, 101);
 showDescription.frame = CGRectMake(85, 140, 330, 65);
 showTime.frame = CGRectMake(130, 10, 149, 119);
 tableBG.frame = CGRectMake(0, 0, 480, 320);

}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
 self.navigationItem.title = CurrentTitle; 
 [showDescription setEditable:NO];
 //show the description
 showDescription.text = showDescriptionInfo;
 showTime.text = showTimeInfo;
 NSString *Path = [[NSBundle mainBundle] bundlePath];
 NSString *ImagePath = [Path stringByAppendingPathComponent:logoName];
 UIImage *tempImg = [[UIImage alloc] initWithContentsOfFile:ImagePath];
 [showLogo setImage:tempImg];
 [tempImg release];
 [self masterView];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 return YES;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
 isLandscape = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
 if(isLandscape = YES){
 [self layoutSubviews];

 }

}





- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}


- (void)dealloc {
 [logoName release];
 [showLogo release];
 [showDescription release];
 [showDescriptionInfo release];
    [super dealloc];
}


@end

I have an TabBar app that I would like to be in landscape and portrait. The issue is when I go to tab 2 make a selection from my table then select tab 1 and rotate the device, then select tab 2 again the content does not know that the device rotated and will not display my custom orientated content correctly. I am trying to write a priovate method that tells the view what orientation it is currently in. IN viewDidLoad I am assuming it is in portrait but in shouldAutoRotate I have it looking in the private method for the correct alignment of the content. Please Help!! Here is my code:

#import "DetailViewController.h"
#import "ScheduleTableViewController.h"
#import "BrightcoveDemoAppDelegate.h"
#import "Constants.h"

@implementation DetailViewController


@synthesize CurrentLevel, CurrentTitle, tableDataSource,logoName,showDescription,showDescriptionInfo,showTime, showTimeInfo, tableBG;

- (void)layoutSubviews {

 showLogo.frame = CGRectMake(40, 20, 187, 101);
 showDescription.frame = CGRectMake(85, 140, 330, 65);
 showTime.frame = CGRectMake(130, 10, 149, 119);
 tableBG.frame = CGRectMake(0, 0, 480, 320);

}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
 self.navigationItem.title = CurrentTitle; 
 [showDescription setEditable:NO];
 //show the description
 showDescription.text = showDescriptionInfo;
 showTime.text = showTimeInfo;
 NSString *Path = [[NSBundle mainBundle] bundlePath];
 NSString *ImagePath = [Path stringByAppendingPathComponent:logoName];
 UIImage *tempImg = [[UIImage alloc] initWithContentsOfFile:ImagePath];
 [showLogo setImage:tempImg];
 [tempImg release];
 [self masterView];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 return YES;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
 isLandscape = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
 if(isLandscape = YES){
 [self layoutSubviews];

 }

}





- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}


- (void)dealloc {
 [logoName release];
 [showLogo release];
 [showDescription release];
 [showDescriptionInfo release];
    [super dealloc];
}


@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征﹌骨岁月お 2024-09-04 20:35:52

我相信您需要将 -shouldAutorotateToInterfaceOrientation: 方法传递给每个视图控制器。您可以在 UITabBarController 中执行类似的操作:

- ( BOOL )shouldAutorotateToInterfaceOrientation:( UIInterfaceOrientation )
          interfaceOrientation
{
    for ( UIViewController *viewController in [ self viewControllers ])
        [ viewController
           shouldAutorotateToInterfaceOrientation:interfaceOrientation ];

    return YES;
}

I believe that you need to pass the -shouldAutorotateToInterfaceOrientation: method to each view controller. You could do something like this in your UITabBarController:

- ( BOOL )shouldAutorotateToInterfaceOrientation:( UIInterfaceOrientation )
          interfaceOrientation
{
    for ( UIViewController *viewController in [ self viewControllers ])
        [ viewController
           shouldAutorotateToInterfaceOrientation:interfaceOrientation ];

    return YES;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文