- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个应用程序不会在 -init 和 -viewWillLayoutSubviews 方法之外设置框架的问题。当点击 editButton 时应该发生的是一个隐藏编辑器 View 的动画。尽管如此,当我测试它时没有任何反应。问题不是来自动画方法,因为 -setFrame 方法(未包含在 block 中)也不起作用。
代码如下:
-(id)init {
if (self = [super init]) {
editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButtonTapped)];
doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonTapped)];
editor = [[UIView alloc] init];
[editor setBackgroundColor:[UIColor yellowColor]];
editor.clipsToBounds = YES;
editorIsOpen = YES;
portraitRegularModeEditorRect = CGRectMake(15, 59, 738, 100);
portraitClosedEditorEditorRect = CGRectMake(15, 59, 738, 0);
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] addSubview:editor];
[[self view] setBackgroundColor:[UIColor blueColor]];
}
-(void)viewDidAppear:(BOOL)animated {
[self setForRegularMode];
}
-(void)viewWillLayoutSubviews {
UIInterfaceOrientation io = [[UIApplication sharedApplication] statusBarOrientation];
if (io == UIInterfaceOrientationPortrait || io == UIInterfaceOrientationPortraitUpsideDown) {
//portrait
[editor setFrame:portraitRegularModeEditorRect];
} else {
//landscape
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)editButtonTapped {
[self setForScenarioLinesEditingMode];
}
-(void)doneButtonTapped {
[self setForRegularMode];
}
-(void)setForRegularMode {
editingMode = CPRegularMode;
if (!editorIsOpen) {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationCurveEaseOut animations:^(void){
[editor setFrame:portraitRegularModeEditorRect];
} completion:^(BOOL finished) {
editorIsOpen = YES;
}];
}
[[self navigationItem] setRightBarButtonItems:[[NSArray alloc] initWithObjects:editButton,nil]];
}
-(void)setForScenarioLinesEditingMode {
editingMode = CPScenarioLinesEditingMode;
if (editorIsOpen) {
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^(void){
[editor setFrame:portraitClosedEditorEditorRect];
} completion:^(BOOL finished) {
editorIsOpen = NO;
}];
}
[[self navigationItem] setRightBarButtonItems:[[NSArray alloc] initWithObjects:doneButton,nil]];
}
如果有人可以提供帮助,请提前致谢;)
最佳答案
我认为你的问题是在你设置的 -(void)viewWillLayoutSubviews
方法中,假设你的 View 的默认框架,如果你试图改变其他框架在您的 View 上调用 setFrame 方法后,-(void)viewWillLayoutSubviews
也将被调用,并且 View 的框架将是默认框架。尝试从您的 -(void)viewWillLayoutSubviews
中删除 setFrame。
关于ios - setFrame 不会做任何事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16220531/
在使用 setFrame 重新绘制框架后,我的转换不绘制。 我在使用 setFrame 更改方向时缩放 View 。但此 View 还需要根据 BOOL 参数更改位置:On = 在 View 中向上,
我尝试在我的 NSWindow 上调用 setFrame:display:animate: 并且没有执行任何操作,但是如果我在同一个窗口上调用 setFrame:display:,它有效。 我需要做其
我为同一 View 多次调用 setFrames。 例如,在设置 ltr View 框架后,我检查布局是否应为 rtl 并再次更改 View 框架。 -(void)setViewsFrames:(BO
我使用下面的代码来设置 iOS 设备上方向发生变化时的 View 。这可以给我想要的形状(更宽和相同的高度),但是改变方向时动画会跳跃。如果我隐藏 setFrame 代码,动画将非常平滑,但形状当然不
我有一个应用程序不会在 -init 和 -viewWillLayoutSubviews 方法之外设置框架的问题。当点击 editButton 时应该发生的是一个隐藏编辑器 View 的动画。尽管如此,
所以我正在为一个更大的项目测试 JSlider,但无法让它工作。 slider 应该调整圆的大小,但它不起作用。我想我可能在创建圆时遇到问题,我正在尝试使用 setFrame,但它给出了一个错误,指出
我正在尝试向 tableviewheader 添加分段控件。我正在使用以下代码来做到这一点 UISegmentedControl *segmentedControl = [[UISegmentedCo
我从我的应用程序收到此崩溃报告,这似乎是在滚动 UICollectionView 时发生的。这是一个很少发生的崩溃,当我设法在 Xcode 中捕获它时,也不知道是哪段代码导致了它。我的 UIColle
在我的 Swift 项目中,我使用了 obj-c 框架。到目前为止它工作正常,但我正在尝试将一些在 obj-c 上编写的旧代码转换为 Swift。 除了这行代码,我设法翻译了所有内容: [[self.
您好,我有一段代码只有一行不起作用... [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEas
我想确保我的 View 都没有错位,因此我想在所有 uiview 上设置框架时使用 CGRectIntegral。但我不想让所有开发人员都像他们通常那样设置框架(例如 view.frame = aCG
在我的应用程序中,我需要一次显示同一 NIB 的多个窗口,并且它将根据计时器关闭/释放, 一切工作正常,除了窗口位置。我的要求是,它应该将窗口显示在前一个窗口的正下方,如果存在相同 NIB 的任何窗口
全部。当我使用 NSTableView 时,只要到达这个函数就会出现以下错误。 -(id)tableView:(NSTableView *)tableView viewForTableColumn:(
我想将图像放置在位置 (10,10,60,60)。我编写了代码,但图像从角落显示。代码 [cell.imageView setFrame:CGRectMake(10,10,60,60)]; 无效。 i
我目前正在调试我们的应用程序中的一个问题,UITextView 的最后几行被切断。 UITextView 位于 collectionView 单元格内,该单元格允许其自身折叠。我试图在框架更改时捕获文
这是我第一次以编程方式添加 UI 元素。该应用因错误而崩溃: 2014-01-14 18:39:50.080 Convention[27580:70b] -[__NSCFConstantString
我正在尝试像这样将 AVCaptureVideoPreviewLayer 添加到我的 View 中 [captureVideoPreviewLayer setFrame:CGRectMake(10.0
我正在尝试根据标签中的文本量更改 UILabel 的高度。 我可以计算标签所需的大小,但是当我尝试设置 UILabel 框架时,它并没有改变。 下面是我的代码。即使我将最后一行中的 size.heig
我有一个正在重构的 Objective-C 项目,我遇到了一行我无法翻译的内容,而且 Apple 的文档站点似乎已关闭: [self.stepperView setFrame:self.stepper
我正在尝试使(10.10 中的新功能)NSSplitViewItem 折叠和展开,同时移动它的包含窗口,以便将整个东西保持在“原位”。 问题是我在动画中出现抽搐(如 here 所示)。 我进行折叠的代
我是一名优秀的程序员,十分优秀!