我试图动画的变化cornerRadius一个的UIView实例layer,但的变化cornerRadius立即生效.
这是代码:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
view.layer.masksToBounds = YES;
view.layer.cornerRadius = 10.0;
[UIView animateWithDuration:1.0 animations:^{
[view.layer.cornerRadius = 0.0;
}];
Run Code Online (Sandbox Code Playgroud)
谢谢大家给我任何提示.
编辑:我设法Core Animation使用a 来动画这个属性CABasicAnimation.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSNumber numberWithFloat:10.0f];
animation.toValue = [NSNumber numberWithFloat:0.0f];
animation.duration = 1.0;
[viewToAnimate.layer addAnimation:animation forKey:@"cornerRadius"];
[animation.layer setCornerRadius:0.0];
Run Code Online (Sandbox Code Playgroud) 我正在努力将广告提供商集成到我的应用中.我希望在广告显示但广告不完整时,在广告前面放置一条淡化消息.
我创建了一个函数,它在我当前的视图中添加了一个子视图,并试图将它带到前面
[self.view bringSubviewToFront:mySubview]
Run Code Online (Sandbox Code Playgroud)
该功能会在加载广告的通知时触发(通知来自广告提供商的SDK).但是,我的子视图不会在广告前面结束.我认为这是广告提供商故意制作的,但我希望无论如何都这样做.我目前正在与提供商讨论是否允许这样做.但就目前而言,我只是想看看它是否可能.
反正我是否可以强迫我的子视图成为最顶级的视图,这样它就不会受到任何阻碍?
早些时候,我在我的项目中使用iOS 6.1.最近我已经切换到iOS 7.因为,我知道很多变化,我更新了我的代码..但我发现了一个奇怪的行为.我在每个屏幕上的视图都隐藏在导航栏下方.重新定位视图解决了iOS7的问题,但是为旧的iOS版本带来了问题.
任何人都可以解释我,原因是什么,为什么会发生?在iOS 7中发生了哪些变化导致了这个问题?
任何帮助,将不胜感激..
在执行长任务时,在Swift IOS应用程序中加载叠加层的示例是什么.从远程服务器加载数据的示例.我用谷歌搜索,但没有找到任何答案.
更新:
感谢@Sebastian Dressler这是一个简单的方法.我更新了我的代码并且运行很酷
public class LoadingOverlay{
var overlayView = UIView()
var activityIndicator = UIActivityIndicatorView()
class var shared: LoadingOverlay {
struct Static {
static let instance: LoadingOverlay = LoadingOverlay()
}
return Static.instance
}
public func showOverlay(view: UIView) {
overlayView.frame = CGRectMake(0, 0, 80, 80)
overlayView.center = view.center
overlayView.backgroundColor = UIColor(hex: 0x444444, alpha: 0.7)
overlayView.clipsToBounds = true
overlayView.layer.cornerRadius = 10
activityIndicator.frame = CGRectMake(0, 0, 40, 40)
activityIndicator.activityIndicatorViewStyle = .WhiteLarge
activityIndicator.center = CGPointMake(overlayView.bounds.width / 2, overlayView.bounds.height / 2)
overlayView.addSubview(activityIndicator)
view.addSubview(overlayView)
activityIndicator.startAnimating() …Run Code Online (Sandbox Code Playgroud) 我的iPhone应用程序中有各种视图需要填充,例如左边是文本对齐的自定义UIButton,背景颜色为UILabel.
这可能是一个非常愚蠢的问题,但我如何应用'填充'来移动左边的文本?
我已经厌倦了使用边界等没有任何成功.
我知道我可以UILabel用背景颜色为我创建一个包装器视图,但它看起来有点矫枉过正.
非常感谢.
我问这个(某种程度上)简单的问题只是为了挑剔,因为有时候我担心我可能会对许多UIView的API进行误操作,特别是在涉及自动布局时.
为了使它变得非常简单,我将使用一个例子,假设我需要一个具有图像图标和多行标签的UIView子类; 我想要的行为是我的视图高度随着标签的高度而变化(以适应文本内部),而且,我正在使用Interface builder进行布局,所以我有这样的事情:

使用一些约束来为图像视图提供固定的宽度和高度,并将固定的宽度和位置(相对于图像视图)固定到标签:

现在,如果我在标签上设置了一些文本,我希望视图在高度上调整大小以适应它,或者保持与xib中相同的高度.在自动布局之前我会做到这样的事情:
在CustoView子类文件中,我会sizeThatFits:像这样重写:
- (CGSize) sizeThatFits:(CGSize)size{
//this stands for whichever method I would have used
//to calculate the height needed to display the text based on the font
CGSize labelSize = [self.titleLabel intrinsicContentSize];
//check if we're bigger than what's in ib, otherwise resize
CGFloat newHeight = (labelSize.height <= 21) ? 51: labelSize.height+20;
size.height = newHeight;
return size;
}
Run Code Online (Sandbox Code Playgroud)
而且我会称之为:
myView.titleLabel.text = @"a big text to display that should be more than a line";
[myView …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来padding向UIView 添加属性.理想情况下,我想避免子类化并将其放入类别中.用法如下:
myview.padding = UIEdgeInsetsMake(10, 10, 10, 10);
Run Code Online (Sandbox Code Playgroud)
也许还有一个paddingBox属性,它将返回CGRect描述内部填充盒的大小和位置.
现在,如何在类别中实现类似的东西.我最初虽然使用bounds,但不幸的bounds是,它的大小与frame(总是相同)的大小相关联,只有坐标可以不同.
我在启动时修改UIView高度时遇到问题.
我必须UIView,我想要一个屏幕尺寸*70和另一个填补空白.
这就是我所拥有的
@IBOutlet weak var questionFrame: UIView!
@IBOutlet weak var answerFrame: UIView!
let screenSize:CGRect = UIScreen.mainScreen().bounds
Run Code Online (Sandbox Code Playgroud)
和
questionFrame.frame.size.height = screenSize.height * 0.70
answerFrame.frame.size.height = screenSize.height * 0.30
Run Code Online (Sandbox Code Playgroud)
它在运行时对应用程序没有影响.我使用自动布局,但我只有边距约束...
我做错了吗?
在ViewController中,ViewDidLoad可以知道VC何时加载.
对于UIView,在加载视图时我必须使用什么方法?
是否可以使用任何init调用此方法?
编辑:没有XIB,只是以编程方式.
在目标c中,它可以在init方法中完成
-(id)init{
self = [[[NSBundle mainBundle] loadNibNamed:@"ViewBtnWishList" owner:0 options:nil] objectAtIndex:0];
return self;
}
Run Code Online (Sandbox Code Playgroud)
但是当我快速地这样做时
init(frame: CGRect) {
self = NSBundle.mainBundle().loadNibNamed("ViewDetailMenu", owner: 0, options: nil)[0] as? UIView
}
Run Code Online (Sandbox Code Playgroud)
无法在方法中分配给self自己显示错误.现在我的方法是创建一个视图,并将从nib加载的视图添加到它.谁都有更好的主意?
uiview ×10
ios ×6
iphone ×3
swift ×3
autolayout ×1
cgsize ×1
cocoa-touch ×1
cornerradius ×1
height ×1
ios7 ×1
objective-c ×1
overlay ×1
padding ×1
subview ×1
uibutton ×1
uikit ×1
uilabel ×1
xcode6 ×1
xib ×1