从弹出窗口更改字体以获取基础滚动视图

时间:2012-11-05 13:57:24

标签: ios fonts uiscrollview popover delegation

我正在使用Xcode 4.5,目标是iOS5及更高版本。 我有一个弹出窗口,允许用户更改底层视图的字体。 点击字体时,更改不会发生,直到我关闭弹出窗口和底层视图并重新打开。 它是为授权而设立的。接收视图会导入FontsPopoverViewDelegate。 我们将非常感谢您对解决方案的任何帮助。

字体的委托方法:

@protocol FontsPopoverViewDelegate <NSObject>
- (void)fontResize:(float)size forView:(int)type;
- (void)font:(int)fontID forView:(int)fView;
- (int)getFontForView:(int)fView;
- (float)getFontSizeForView:(int)fView;
@end

在基础视图中实现的方法:

- (void)fontResize:(float)size forView:(int)type {
  fontSizes[type] = size;
  [self invalidate];
}

- (void)font:(int)fontID forView:(int)fView {
  fontIds[fView] = fontID;
  [self invalidate];
}

- (int)getFontForView:(int)fView {
  return fontIds[fView];
  [self invalidate];
}

- (float)getFontSizeForView:(int)fView {
  return fontSizes[fView];
  [self invalidate]; // added to spark a reaction from the view
}

-(void) invalidate {
  NSLog(@"Invalidate called");
  [self saveTextChanges];
  [self refreshBodyText];
  [self refreshBackground];
  [self refreshBodyText];
  [self refreshDateFont];
  [self refreshTitleFont];
}

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我通过从字体弹出窗口向底层视图发布通知来解决此问题。在底层视图中,我添加了调用... [self viewWillAppear:YES];

现在,它完美运作。

我在字体弹出窗口中有一个滑块,用于更改大小和通知,并且通知中的viewWillAppear与字体更改的工作方式相同。

- (void)aFontChanged:(NSNotification *)notification
{
    NSLog(@"aFontChanged notification?");
    [self viewWillAppear:YES];
    [self refreshBodyText];
    [self refreshDateFont];
    [self refreshTitleFont];
}

- (void)aFontSizeChanged:(NSNotification *)notification
{
    NSLog(@"aFontSizeChanged notification?");
    [self viewWillAppear:YES];
    [self refreshBodyText];
    [self refreshDateFont];
    [self refreshTitleFont];
}