我正在开发一个应用程序,左侧有一个"抽屉"非常有用.我正在做一些初步测试,看看我最好能做到这一点,而且我遇到了一些非常基本的麻烦.
我的设置
1.我在Xcode 4中使用单视图应用程序模板
.2.在xib的"主/边界"视图中,我添加了2个UIViews(LeftPanel和RightPanel)和一个UIButton(ShowHideButton).
我为LeftPanel绿色和RightPanel蓝色着色,以便更容易看到.
4.加载视图时,两个面板都可见,UIButton的文本为"隐藏面板".
5.按下按钮后,LeftPanel应滑离屏幕(向左),RightPanel应展开以占据其原始空间加上LeftPanel腾出的空间.
6.此时,ShowHideButton应将其文本更改为"显示面板".
7.再次按下按钮后,LeftPanel应向后滑动到屏幕上(从左侧),RightPanel应缩小到"将其返回"原始空间.
8.此时,ShowHideButton应将其文本更改回"隐藏面板".
我正在使用实现动画animateWithDuration:animations:completion:.到目前为止,过渡关闭屏幕工作正常(非常好,其实).
令我不安的是,当我尝试将LeftPanel"带回"时,我得到了一个EXC_BAD_ACCESS.我已经在下面发布了我的代码,我已经看了它,但我真的看不到我正在访问的内容(或者是导致EXC_BAD_ACCESS的任何内容).
DrawerTestingViewController.h
#import <UIKit/UIKit.h>
typedef enum {
kHidden,
kShown
} PanelState;
@interface DrawerTestingViewController : UIViewController {
PanelState currentState;
UIButton *showHideButton;
UIView *leftPanel;
UIView *rightPanel;
}
@property (assign, nonatomic) PanelState CurrentState;
@property (strong, nonatomic) IBOutlet UIButton *ShowHideButton;
@property (strong, nonatomic) IBOutlet UIView *LeftPanel;
@property (strong, nonatomic) IBOutlet UIView *RightPanel;
- (IBAction)showHidePressed:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
DrawerTestingViewController.m
#import "DrawerTestingViewController.h"
@implementation DrawerTestingViewController
@synthesize CurrentState = currentState;
@synthesize LeftPanel = leftPanel; …Run Code Online (Sandbox Code Playgroud)