我希望我的整個項目,在縱向模式下運行,並僅這是觀看照片的視圖可以打開的風景一樣,如果使用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
和PhotoViewC ontroller.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類,以便獲得我想要的效果嗎?...任何代碼幫助都將非常有幫助..預先感謝貢獻你的時間
總之我有兩兩件事要做:
我一定要限制我的項目只肖像模式只留下照片的看法有橫向/縱向兼容。
我目前在我的表格視圖中顯示照片,我希望在選擇時以與FB或其他應用在查看照片時的相同樣式(風景/肖像兼容)中打開。
你可以設置從摘要窗口具體orentation。禁用所有其他支持的方向。它會正常工作。 – Anjan
不,但他也想景觀... – IronManGill
是的..這就是爲什麼我卡住了? – iOSBee