プロジェクト全体をポートレートモードでのみ実行し、写真を表示するためのビューのみがFacebookを使用する場合と同じようにランドスケープをオンにできます(写真を表示するとランドスケープもオンになりますが、他のビューはポートレートのままになります)サーバーからDBから取得した画像を含むテーブルビューがあり、特定のデータごとに異なる数の写真が含まれているため、ユーザーが写真を選択した後、写真を完全に開いて表示できるようにします。横向きでも縦向きでも試してみました
私はios6で作業しています
- (BOOL)shouldAutorotate
{
return NO;
}
すべてのビューに実装して、縦向きのままでも横向きのままにできるようにするには、どのように制限すればよいですか?クラスの1つで、テーブルビュー(DBからロード)に画像があり、テーブルから選択した写真を開く別のクラスがあります
私の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クラスで1枚の写真を取得するPhotoViewControllerクラスにすべての写真を追加して、必要な効果を得る方法を教えてもらえますか?...コードヘルプは非常に役立ちます..貢献してくれてありがとうあなたの時間
要するに、私は2つのことをする必要があります:
横向き/縦向きの互換性を持たせるために、プロジェクトを縦向きモードのみに制限し、写真のビューのみを残す必要があります。
私は現在、写真を表示しているときにFBまたは他のアプリと同じスタイル(風景/ポートレート互換)で開くように選択したい写真をテーブルビューに表示しています。