我做了一个自定义的@IBDesignable UIView,只实现了drawRect函数.像这样:
@IBDesignable
class CustomView: UIView {
override func drawRect(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
// Lots more drawing code after this
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
当我写这个drawRect时,我在视图控制器上有一个故事板,其中有几个不同的渲染实例.当我在drawRect中进行更改并保存时,这些更改将在接近实时的情况下反映在故事板中.甚至有一个IBInspectable String允许我更改枚举类型并根据不同的方式绘制.可以在故事板中调整视图的大小,并在我的绘图代码中考虑新的宽度和高度,并且绘图将按照我的预期进行缩放和翻译.
这一切都运行正常,我没有对该UIView子类进行任何更改,但我确实删除了故事板中的测试视图,同时构建了实际上最终使用此自定义视图的新视图.
在做了大量的约束跳舞后,我准备将我的自定义视图放在它所属的位置.但它不起作用.身份检查员将我的自定义类确认为IBDesignable时,它会挂起"正在更新"状态.
为了证明我没有疯狂,我创建了全新的@IBDesignable UIView子类,它实现了简单的drawRects甚至是完全空的drawRects.这些现在具有相同的问题,并且不在故事板上呈现.
请注意,我可以在模拟器中运行它,并且绘图显示为我在运行时所期望的.那么故事板能够提供我期望从IBDesignable那里得到的好反馈呢?
我尝试过的事情:
所有这些尝试继续在身份检查器的"自定义类"部分中显示"正在更新".
显然,我实施之外的东西在这里引起了一个问题.还有其他人有这个问题吗?任何人都能指出我正确的方向吗?不知道还有什么可以尝试.
我已经实现了一个自定义身份验证过滤器,并且效果很好。我使用外部身份提供程序并在设置会话并将我的身份验证对象添加到我的安全上下文后重定向到我最初请求的 URL。
安全配置
@EnableWebSecurity(debug = true)
@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
// this is needed to pass the authentication manager into our custom security filter
@Bean
@Override
AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean()
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
//.antMatchers("/admin/test").hasRole("METADATA_CURATORZ")
.antMatchers("/**").permitAll()
.anyRequest().authenticated()
.and()
.addFilterBefore(new CustomSecurityFilter(authenticationManagerBean()), UsernamePasswordAuthenticationFilter.class)
}
}
Run Code Online (Sandbox Code Playgroud)
过滤逻辑
现在,我的自定义过滤器(一旦确认身份)只是硬编码一个角色:
SimpleGrantedAuthority myrole = new SimpleGrantedAuthority("METADATA_CURATORZ")
return new PreAuthenticatedAuthenticationToken(securityUser, null, [myrole])
Run Code Online (Sandbox Code Playgroud)
然后在重定向到所需端点之前,该身份验证对象(上面返回)被添加到我的 SecurityContext 中:
SecurityContextHolder.getContext().setAuthentication(authentication)
控制器端点
@RequestMapping(path = '/admin/test', method = GET, produces …
Run Code Online (Sandbox Code Playgroud)