2011-11-18 22 views
5

Tôi mới sử dụng hoạt ảnh và tôi đang sử dụng mã sau cho hoạt ảnh Lật.Hoạt ảnh trên iPhone: Làm cách nào để tạo hoạt ảnh cho chế độ xem phụ? Không phải toàn bộ quan điểm?

//MyMapView is UIView 

MyMapView *aMapView = [[MyMapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300) AndResArray:self.nearMeArray]; 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; 
    [[self view] addSubview:nearMeMap]; 

    [UIView commitAnimations]; 

Làm việc tốt. Nhưng toàn bộ xem (với siêu xem) Flips.

Tôi chỉ muốn lật tiểu sử là MyMapView. Chế độ xem siêu không được lật.

Cách thực hiện việc này ???

EDITED

màn hình:

Dưới đây là màn hình chính. Khi nhấp vào nút Bản đồ, tôi chỉ muốn lật phần Nâu của màn hình. Toàn bộ màn hình không được lật.

enter image description here

Thanks ...

+0

Bạn cần dán chế độ xem của mình để tạo hoạt ảnh vào một chế độ xem phụ khác. – Borzh

Trả lời

3

Tôi đã tìm ra vấn đề là gì. Vui lòng xem mã bên dưới.

MapView.m

- (id)initWithFrame:(CGRect)frame { 

self = [super initWithFrame:frame]; 
if (self) { 
    // Initialization code. 

    [self performSelector:@selector(addMapView) withObject:nil afterDelay:2.0]; 

} 
return self; 
} 

- (void) addMapView { 

//MyMapView is UIView 

MKMapView *aMapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 321, 300)]; 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.0]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES]; 
[self addSubview:aMapView]; 

[UIView commitAnimations]; 

} 

Và sau đó chỉ cần thêm đối tượng của lớp MapView nơi bạn muốn. như dưới đây.

//MyMapView is UIView 
mapView *aMapView = [[mapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300)]; 
[[self view] addSubview:aMapView]; 

bỏ phiếu nếu nhận xét này giúp bạn.

Xin cảm ơn,

MinuMaster.

+0

cảm ơn mã tuyệt vời .... một điều nữa khi tôi tạo hiệu ứng cho nó nền sẽ bị xóa. bất kỳ ý tưởng? – Maulik

+0

Chế độ xem bản đồ nền ??? hoặc Super Xem nền. – MinuMaster

+0

Tham gia phòng Trò chuyện. – MinuMaster

1

Bạn cần phải thêm quan điểm của bạn để self.view và sau đó lật chỉ aMapView:

MyMapView *aMapView = [[MyMapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300) AndResArray:self.nearMeArray]; 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.0]; 
[self.view addSubView:aMapView]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:aMapView cache:YES]; 

[UIView commitAnimations]; 
+0

Tôi đã thử nó trước khi ... không có gì xảy ra..chỉ aMapView được hiển thị mà không có bất kỳ hoạt ảnh nào !!! Đã cập nhật – Maulik

+0

câu trả lời. Có thể bạn cần phải thêm chế độ xem trong khối. –

+0

Tôi nghĩ rằng tôi đã làm điều tương tự! – Maulik

1

chuyển đổi động như thế này animate nội dung của một cái nhìn . Hệ thống sẽ chụp nhanh các nội dung ở phần đầu của hoạt ảnh, một ảnh chụp khác khi bạn cam kết, và sau đó hoạt ảnh giữa chúng. Như bạn đã thấy với mã ban đầu của mình, toàn bộ chế độ xem được làm động.

Giải pháp đơn giản nhất có lẽ là chỉ giới thiệu chế độ xem trung gian là kích thước và vị trí của bản đồ sẽ đi đến đâu. Sau đó tạo hiệu ứng rằng chế độ xem khi bạn thêm bản đồ vào đó.

Thông tin thêm trong phần Hướng dẫn lập trình xem trên Creating Animated Transitions Between Views. Mặc dù các phương pháp bạn đang sử dụng có, trong iOS 4, được superceded bởi các phiên bản dựa trên khối mới.

+0

Chế độ xem trung gian là nó! – Borzh

2

Câu trả lời của Matteo đúng một phần, nhưng bạn cần đặt hoạt ảnh trên chế độ xem trước khi thêm hoặc nó sẽ không hoạt động chính xác. Như thế này:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.0]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 
         forView:aMapView 
         cache:YES]; 
[self.view addSubview:aMapView]; 
[UIView commitAnimations]; 

Hoặc, bạn có thể sử dụng API dựa trên khối được giới thiệu trong iOS 4. Dưới đây là ví dụ.

[UIView transitionWithView:aMapView 
     duration:1.0 
     options:UIViewAnimationTransitionFlipFromRight 
     animations:^{ [self.view addSubview:aMapView]; } 
     completion:^(BOOL f){ } 
]; 
0
-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    OptionView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)]; 
    OptionView.backgroundColor=[UIColor blueColor]; 
    OptionIsShow=false; 

    MoveView=[[UIView alloc] initWithFrame:CGRectMake(40, 40, 70, 70)]; 
    [MoveView setBackgroundColor:[UIColor redColor]]; 
    [self.view addSubview:MoveView]; 

} 

-(void)ViewOrHideOptionView 
{ 

     CGContextRef context = UIGraphicsGetCurrentContext(); 
     [UIView beginAnimations:nil context:context]; 

     [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.MoveView cache:NO]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDuration:1.0]; 

     if(!OptionIsShow) 
     { 
      [self.MoveView addSubview:OptionView]; 
      OptionIsShow=true; 
     } 
     else 
     { 
      [self.OptionView removeFromSuperview]; 
      OptionIsShow=false; 
     } 

     [UIView commitAnimations]; 
} 
Các vấn đề liên quan