0

我希望我的整个项目仅在纵向模式下运行,并且只有用于查看照片的视图才能像使用 facebook 一样打开横向(我们查看照片的它们也会变成横向,但其他视图仍然是纵向的)我想知道它是如何完成的,因为我有一个表格视图,其中包含我从服务器从数据库获取的图像,并且每个特定数据都包含不同数量的照片,所以现在我希望在用户选择照片后,它们应该完全打开并且可以查看在风景和肖像中,我也尝试过

我正在使用 ios6

- (BOOL)shouldAutorotate
{
    return NO;
}

在所有视图中实现,以便它们可以保持纵向,但它们仍然是横向的,我应该如何限制它,请任何人告诉我,在我的一堂课中,我在表格视图中有图像(从数据库加载),我有另一个课程可以打开表格中选定的照片

我的 PhotoView.m 类

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSDictionary *dic = [photos objectAtIndex:indexPath.row];
    NSLog(@" *** url is %@",[dic objectForKey:@"url"]);
    [self.delegate showPhotoAtUrl:[dic objectForKey:@"url"]];
 }

我的 PhotoViewController.h 类

   #import <UIKit/UIKit.h>

@interface PhotoViewController : UIViewController <UIScrollViewDelegate>
{
    NSString *url;
    UIButton *doneButton;
}

@property (nonatomic, retain) UIImageView *imageView;

- (id) initWithPhotoUrl:(NSString *)photoUrl;

@end

和 PhotoViewController.m 类

#import "PhotoViewController.h"

@interface PhotoViewController ()

@end

@implementation PhotoViewController

@synthesize imageView;

- (id) initWithPhotoUrl:(NSString *)photoUrl
{
    self = [super init];
    if(self) {
        url = [photoUrl retain];
    }
    return self;
}

- (void)dealloc
{
    [url release];
    self.imageView = nil;
    [doneButton release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    spinner.tag = 1;
    spinner.center = self.view.center;
    [spinner startAnimating];
    [self.view addSubview:spinner];
    [spinner release];
    [self performSelectorInBackground:@selector(loadPhotoData) withObject:nil];

    doneButton  = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
    [doneButton addTarget:self action:@selector(doneTouched) forControlEvents:UIControlEventTouchUpInside];
    [doneButton setTitle:@"done" forState:UIControlStateNormal];
    [doneButton setBackgroundColor:[UIColor clearColor]];    
    doneButton.frame = CGRectMake(2, 2, 60, 30);
    [self.view addSubview:doneButton];
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.title = @"";
    self.navigationController.navigationBarHidden = YES;
}

- (void) doneTouched
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void) loadComplete:(NSData *)imageData
{
    if(!imageData) return;

    UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)[self.view viewWithTag:1];
    if(spinner) {
        [spinner stopAnimating];
        [spinner removeFromSuperview];
    }

    UIImage *img = [UIImage imageWithData:imageData];

    float scale = MIN(self.view.frame.size.width/img.size.width, self.view.frame.size.height/img.size.height);
    self.imageView = [[[UIImageView alloc] initWithImage:img] autorelease];
    self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width*scale, self.imageView.image.size.height*scale);

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    self.imageView.center = scrollView.center;
    scrollView.delegate = self;
    scrollView.contentSize = self.imageView.frame.size;
    scrollView.minimumZoomScale = 1;
    scrollView.maximumZoomScale = 2;
    [scrollView addSubview:self.imageView];
    [self.view addSubview:scrollView];
    [scrollView release];

    [self.view bringSubviewToFront:doneButton];
}

- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;
}

- (void) loadPhotoData
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
    [self performSelectorOnMainThread:@selector(loadComplete:) withObject:imageData waitUntilDone:NO];
    [pool drain];
}

@end

在主类中我有这个方法调用 PhotoViewController 来加载选定的照片

- (void) showPhotoAtUrl:(NSString *)url
{

    PhotoViewController *vc = [[PhotoViewController alloc] initWithPhotoUrl:url];
    [self.navigationController pushViewController:vc animated:YES];
    [vc release];
}

现在我的问题是我应该如何在从表格中选择后获取图像以在 FB 应用程序中打开的相同类型的视图中打开(在纵向/横向兼容视图中打开所选照片)我只能在我的 PhotoViewController 类中获取一张照片谁能告诉我如何将所有照片添加到 PhotoViewController 类中,以便获得我想要的效果?...任何代码帮助都会非常有帮助..提前感谢您的贡献您的时间

简而言之,我有两件事要做:

  1. 我必须将我的项目限制为仅纵向模式,只留下照片的视图以具有横向/纵向兼容性。

  2. 我目前在我的表格视图中有照片,我希望在查看照片时以与 FB 或其他应用程序相同的样式(横向/纵向兼容)打开。

4

1 回答 1

0
These only work on iOS 6.0

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}
    The method will return which orientation mode to use first.

    Below are supportedInterfaceOrientations:

    UIInterfaceOrientationMaskPortrait
    UIInterfaceOrientationMaskLandscapeLeft
    UIInterfaceOrientationMaskLandscapeRight
    UIInterfaceOrientationMaskPortraitUpsideDown 
    UIInterfaceOrientationMaskLandscape 
    UIInterfaceOrientationMaskAll
    UIInterfaceOrientationMaskAllButUpsideDown

    For iOS > 4.0
        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }


Other ViewControllers will have 
-(BOOL)shouldAutorotate { return NO; } 
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation{     
return NO;
}
于 2013-02-02T08:29:42.240 回答