我见过这样的功能:
public func highlightValues(highs: [ChartHighlight]?)
{
// set the indices to highlight
_indicesToHightlight = highs ?? [ChartHighlight]();
// redraw the chart
setNeedsDisplay();
}
Run Code Online (Sandbox Code Playgroud)
这里的目的是??什么?我搜索过,但似乎搜索??很难找到合适的答案.
我是swift的新手,我看到一些方法,如:
@objc private func doubleTapGestureRecognized(recognizer: UITapGestureRecognizer)
Run Code Online (Sandbox Code Playgroud)
我想知道什么时候使用@objc?我读了一些文档,但是他们说当你希望它在Objective-C中可以调用时,你应该添加@objc标志
但是,这是一个快速的私有函数,@ obj做了什么?
刚刚下载了XCode 7 GM并尝试了我的应用程序的iOS 9模拟器.但是,我在控制台上收到一条奇怪的消息:
objc[2213]: Class _NSZombie_BSXPCMessage is implemented in both ?? and ??. One of the two will be used. Which one is undefined.
然后我用Google搜索,没有运气.如果我在方案设置中禁用启用僵尸对象,则消息将消失.怎么了?
更新:我在Xcode 6.4上再次测试它,没有这个问题.
所以我以前用过:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent
animated:YES];
Run Code Online (Sandbox Code Playgroud)
动画状态栏样式的变化,从暗到亮,反之亦然
但是,自iOS 9起,此方法已弃用.
我更改为使用preferredStatusBarStyle以下@serenn的答案,而不是调用preferredStatusBarStyle
它确实可以改变旧式的状态栏样式,但没有动画.
文件说:
如果此方法的返回值更改,请调用setNeedsStatusBarAppearanceUpdate方法.
但是我不知道在哪里调用它,我试过把它放在viewWillAppear中,但没有运气.
preferredStatusBarUpdateAnimation 仍为默认值:UIStatusBarAnimationFade
所以我很困惑.寻找如何动画为已弃用方法的答案.提前致谢!
我有一个按钮,想要旋转里面的图像:
self.DashButton.imageView.transform = CGAffineTransformMakeRotation(M_PI);
用户点击图像后向上箭头向下箭头当再次点击按钮时,我希望向下箭头再次向上旋转向上箭头,但它是逆时针旋转相同,但我只想让箭头向后反转向上箭头
旋转代码:
self.DashButton.imageView.transform = CGAffineTransformIdentity;
我试过了
self.DashButton.imageView.transform = CGAffineTransformMakeRotation(-M_PI);
我想要的不是旋转整圆,只旋转180度和-180旋转,而不是360度全旋转
由于某些目的(比如拉到刷新),我需要一个UICollectionView可以在没有单元格时弹跳或滚动 - 表示numberOfItemsInSection:返回0
我的代码是这样的:
...
UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.minimumInteritemSpacing = SPLIT_SPACE;
flowLayout.minimumLineSpacing = SPLIT_SPACE;
targetCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - TABBAR_HEIGHT)
collectionViewLayout:flowLayout];
[targetCollection registerNib:[UINib nibWithNibName:@"DashboardCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"DashboardCell"];
targetCollection.autoresizingMask = UIViewAutoresizingFlexibleHeight;
targetCollection.backgroundColor = [UIColor colorWithHex:@"#EAEAEA"];
targetCollection.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
targetCollection.alwaysBounceVertical = YES;
...
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,在测试时,这个空的UICollectionView不能弹跳也不能滚动.我怀疑它与空单元格有关,但我确实需要在没有单元格时启用弹跳或滚动.这类似于我的另一个问题:SVPullToRefresh无法提取空的UICollectionView
所以在Apple文档中:
扩展中添加的任何类型成员具有与要扩展的原始类型中声明的类型成员相同的默认访问级别.如果扩展公共或内部类型,则添加的任何新类型成员都将具有内部的默认访问级别.
给出UIView扩展的子类:
extension UIViewSubClass
{
var helloWorld : String {
get {
return "helloWorld"
}
}
}
Run Code Online (Sandbox Code Playgroud)
这将标记helloWorld为内部,我没有问题,我在基于Objective-C的项目中看不到它.
但是,如果我将扩展标记为公开:
public extension UIViewSubClass
{
var helloWorld : String {
get {
return "helloWorld"
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在helloWorld在我的基于Objective-C的代码中出现,这意味着它被标记为公共.
但是,我没有看到苹果提到这一点,做到了吗?
我刚看到文档说公共类仍然具有隐含的内部级别.
public class SomePublicClass { // explicitly public class
public var somePublicProperty = 0 // explicitly public class member
var someInternalProperty = 0 // implicitly internal class member
private func somePrivateMethod() {} // explicitly private class …Run Code Online (Sandbox Code Playgroud) 我用以下方法画了一个圆弧:
- (void)drawRect:(CGRect)rect {
UIBezierPath *stripePath = [UIBezierPath bezierPath];
[arcColor set];
[stripePath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:clockwise];
stripePath.lineWidth = arcWidth;
stripePath.lineCapStyle = kCGLineCapRound;
stripePath.lineJoinStyle = kCGLineCapRound;
[stripePath stroke];
}
Run Code Online (Sandbox Code Playgroud)
现在我想以角度为这个弧设置动画.
我正在尝试使用类似的东西:
angle = startAngle;
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
angle = endAngle;
[stripePath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:angle clockwise:clockwise];
[stripePath stroke];
}];
Run Code Online (Sandbox Code Playgroud)
但是,屏幕上没有显示动画.如何使用角度作为变化变量来设置弧的动画?谢谢.
所以在文档中,它说:
minimumInteritemSpacingForSectionAtIndex:对于水平滚动网格,此值表示同一列中项目之间的最小间距.
minimumLineSpacingForSectionAtIndex:对于水平滚动网格,此值表示连续列之间的最小间距.
我想如果节数是1,我应该使用minimumInteritemSpacingForSectionAtIndex; 当节数> 1时,我应该使用minimumLineSpacingForSectionAtIndex.
但是,我有一个水平滚动集合视图,节数为1,项目数为2.
当我设置minimumInteritemSpacingForSectionAtIndex返回10时,似乎没有任何反应.当我使用minimumLineSpacingForSectionAtIndex返回10时,左侧单元格和右侧单元格有10个空格边距,似乎正常工作.
所以我很困惑这里的意义same column和successive columns含义.有人能解释一下吗
我知道有一个帖子:通过nib向这个问题添加到UICollectionViewCell contentView,但答案是不正确的.将UILabel直接拖动到单元格的xib中,Label将被添加到单元格本身,而不是其contentView:
(lldb) po self.subviews
<__NSArrayM 0x7fa9b1c58a20>(
<UIView: 0x7fa9b1c77540; frame = (0 0; 64 64); gestureRecognizers = <NSArray: 0x7fa9b1c66260>; layer = <CALayer: 0x7fa9b1c352f0>>,
<UILabel: 0x7fa9b1c7a880; frame = (0 15; 64 18); text = 'market share'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fa9b1c6f820>>,
<UILabel: 0x7fa9b1c77c30; frame = (0 38; 64 22); text = '17.06'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fa9b1c36fe0>>
)
(lldb) po self.contentView.subviews …Run Code Online (Sandbox Code Playgroud)