gpt4 book ai didi

objective-c - NSControl 在全屏模式下附加到 NSView 的 NSView 上闪烁

转载 作者:搜寻专家 更新时间:2023-10-30 19:48:23 27 4
gpt4 key购买 nike

设置:

  1. 我的应用程序具有使用 enterFullScreenMode:withOptions: 设置为全屏模式的背景 View
  2. 对于这些背景 View ,我使用removeFromSuperviewaddSubview:内容 View 作为 subview 移动。
  3. 此外,还有一个首选项 View ,我将其添加到内容 View ,如前所述。
    preferences view 来自 XIB,包含 NSControls,例如复选框、圆形幻灯片、组合框……

整个设置要复杂得多,因此很难在此处发布代码。不过,如果您需要,我会添加一些部分。

问题:
当我选择首选项 View 上的任何控件时,元素会闪烁。这意味着例如复选框会消失并重新出现。我已经尝试解决在 View 的 viewDidMoveToSuperview 方法中运行 setNeedsDisplay:setNeedsLayoutmakeKeyAndOrderFront: 的问题.虽然,没有任何帮助。我能做什么?


编辑 1:我拿了screen capture的应用程序,以便您可以看到发生了什么。


编辑 2:
这是 PreferencesViewController.h:

//  PreferencesViewController.h

#import <Cocoa/Cocoa.h>
#import "SlideShowModelProtocol.h"
#import "DisplayInfoController.h"

@interface PreferencesViewController : NSViewController {
id<SlideShowModelProtocol> m_localModel;
DisplayInfoController* m_displayInfoController;
}

@property (readonly) id<SlideShowModelProtocol> localModel;
@property (readwrite, assign) IBOutlet DisplayInfoController* displayInfoController;

- (void)moveViewToSuperview:(NSView*)superview;
- (void)showOnView:(NSView*)superview;
- (void)removeViewFromSuperview;
- (BOOL)viewHasSuperview;
- (void)updateModelSettings;
- (IBAction)cancelView:(id)sender;
- (IBAction)confirmView:(id)sender;

@end

...和实现PreferencesViewController.m:

//  PreferencesViewController.m

#import "PreferencesViewController.h"
#import "ApplicationController.h"
#import "DisplayInfo.h"


@interface PreferencesViewController()

- (void)centerViewOnSuperview;
- (void)loadModel;

@end

@implementation PreferencesViewController


- (id)init {
self = [super initWithNibName:@"PreferencesView" bundle:nil];
if (self != nil) {
m_localModel = nil;
m_displayInfoController = nil; // Assigned in Interface Builder.
}
return self;
}

@synthesize localModel = m_localModel;
@synthesize displayInfoController = m_displayInfoController;

- (void)loadModel {
[self willChangeValueForKey:@"localModel"];
// Retrieve deep copy of the model.
m_localModel = [[[ApplicationController sharedController] model] copyWithZone:nil];
// Reset the table view selection as saved in the model.
NSIndexSet* selectionIndices = [NSIndexSet indexSetWithIndex:[[m_localModel selectedScreenIndex] unsignedIntegerValue]];
[[m_displayInfoController displayInfoTableView] selectRowIndexes:selectionIndices byExtendingSelection:NO];
[self didChangeValueForKey:@"localModel"];
}

/**
Moves and positions the view on the given superview (aka another screen).
@param superview A superview.
*/
- (void)showOnView:(NSView*)superview {
[self moveViewToSuperview:superview];
[self centerViewOnSuperview];
}

/**
Moves the view on the given superview.
@param superview A superview (In full screen mode a background view).
*/
- (void)moveViewToSuperview:(NSView*)superview {
if ([[self view] superview] == superview) {
return;
}
[self loadModel];
[[self view] removeFromSuperview];
[superview addSubview:[self view]];
}

- (void)removeViewFromSuperview {
[[self view] removeFromSuperview];
}


- (void)centerViewOnSuperview {
NSRect superviewFrame = self.view.superview.frame;
NSRect viewFrame = self.view.frame;
float viewFrameWidth = viewFrame.size.width;
float viewFrameHeight = viewFrame.size.height;
float xPos = 0.5f * superviewFrame.size.width - 0.5f * viewFrameWidth;
float yPos = 0.5f * superviewFrame.size.height - 0.5f * viewFrameHeight;
NSRect frame = NSMakeRect(xPos, yPos, viewFrameWidth, viewFrameHeight);
[self.view setFrame:frame];
}

- (BOOL)viewHasSuperview {
return [[self view] superview] != nil;
}

- (void)updateModelSettings {
id<SlideShowModelProtocol> globalModel = [[ApplicationController sharedController] model];
[globalModel setFadeDuration:[m_localModel fadeDuration]];
[globalModel setStayDuration:[m_localModel stayDuration]];
[globalModel setStartWithFirst:[m_localModel startWithFirst]];
[globalModel setSortingMode:[m_localModel sortingMode]];
[globalModel setAnimationIsActive:[m_localModel animationIsActive]];
[globalModel setSelectedScreenIndex:[m_localModel selectedScreenIndex]];
[globalModel setPanAmount:[m_localModel panAmount]];
[globalModel setZoomAmount:[m_localModel zoomAmount]];
[globalModel setZoomFactor:[m_localModel zoomFactor]];
}

#pragma mark -
#pragma mark UserInterface

- (IBAction)cancelView:(id)sender {
[[ApplicationController sharedController] hidePreferencesViewModelSettingsUpdated:NO];
}

- (IBAction)confirmView:(id)sender {
ApplicationController* applicationController = [ApplicationController sharedController];
if ([[applicationController model] isEqualToModel:m_localModel]) {
[self cancelView:sender];
return;
}
[self updateModelSettings];
[applicationController hidePreferencesViewModelSettingsUpdated:YES];
}

@end

最佳答案

正如我在帖子的评论中所述,我创建了一个新的 PreferencesViewTest.xib 并逐步添加了 GUI 控件。我还添加了绑定(bind)、 Controller 等。一切正常 - 没有闪烁。然后,我将 RETURN 指定为 Interface Builder 中 OK 按钮的等效键。我再次启动应用程序以检查行为......它闪烁!我通过从 OK 按钮中删除 key equivalent 来仔细检查以前的 PreferencesView.xib 的现象......它不会闪烁! - 疯狂的狗屎。但是为什么..?

关于objective-c - NSControl 在全屏模式下附加到 NSView 的 NSView 上闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7013997/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com