我有一個應用程序在一個視圖控制器上有兩個視圖。一種觀點在另一種觀點之上。當有人滑動或按下按鈕時,頂部的視圖移動到側面以顯示底部視圖。當有人打開一個新的視圖並想用兩個視圖返回到視圖控制器時,我希望頂部的視圖自動顯示底部視圖。 這是我的代碼:iOS切換視圖功能
@interface ViewController()
@end
@implementation ViewController
@synthesize topLayer = _topLayer;
@synthesize layerPosition = _layerPosition;
- (void)viewDidLoad
{
[super viewDidLoad]
self.topLayer.layer.shadowOffset = CGSizeMake(-1,0);
self.topLayer.layer.shadowOpacity = .9;
self.layerPosition = self.topLayer.frame.origin.x;
}
#define VIEW_HIDDEN 264
-(void) animateLayerToPoint:(CGFloat)x
{
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
CGRect frame = self.topLayer.frame;
frame.origin.x = x;
self.topLayer.frame = frame;
}
completion:^(BOOL finished){
self.layerPosition =self.topLayer.frame.origin.x;
}];
}
- (IBAction)toggleLayer:(id)sender {
if (self.layerPosition == VIEW_HIDDEN) {
[self animateLayerToPoint:0];
} else {
[self animateLayerToPoint:VIEW_HIDDEN];
}
}
- (IBAction)panLayer:(UIPanGestureRecognizer*)pan {
if (pan.state == UIGestureRecognizerStateChanged) {
CGPoint point = [pan translationInView:self.topLayer];
CGRect frame = self.topLayer.frame;
frame.origin.x = self.layerPosition + point.x;
if (frame.origin.x < 0) frame.origin.x = 0;
self.topLayer.frame = frame;
}
if (pan.state == UIGestureRecognizerStateEnded) {
if (self.topLayer.frame.origin.x <= 160) {
[self animateLayerToPoint:0];
} else {
[self animateLayerToPoint: VIEW_HIDDEN];
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
問題是什麼? – allprog
我需要知道,如何將視圖加載到頂視圖移到一邊,以便在有人按下另一個視圖上的後退按鈕返回到此視圖時顯示第二個視圖。 –
如果你正在使用應該已經發生的導航控制器 – micantox