小编Cod*_*der的帖子

如何获取Video AVAsset的大小(KB)

我想获得一个AVAsset视频文件大小,而不是视频的分辨率,但文件重量是KB.

一个解决方案是从持续时间和estimatedDataRate计算估计的文件大小,但这似乎只是为了获得文件大小.

我已经检查了嵌入AVAssetTrack其中的所有数据似乎没有在那里.即使是估计的文件大小也会很好.

ios avasset

12
推荐指数
3
解决办法
7542
查看次数

创建一个包含两个CGPoints SpriteKit Swift的行

我试图制作一个简单的应用程序,你触摸一个点,一个精灵跟随一条线穿过该点到屏幕的边缘,无论你在哪里触摸.我想绘制连接精灵的原点(它开始的点)和你触摸的点之间的线段,以及精灵的原点和屏幕边缘的终点之间的线段,这样我就可以看到精灵以及原点,触点和终点的x和y偏移之间的关系.

希望这不是太混乱.

TL; DR:我需要在两点之间画一条线,我不知道如何使用SpriteKit Swift.

提前致谢.

ios sprite-kit swift

12
推荐指数
3
解决办法
7133
查看次数

在swift中如何更改SKSpriteNode的颜色?

我创建了一个SKSpriteNode黑色的游戏,当用户触摸屏幕时,我希望将SKSpriteNode其更改为白色.我用谷歌搜索了所有可能的东西,尝试了许多不同的策略而没有运气.有谁知道如何做到这一点?

这是我的场景的代码:

var blackBird = SKSpriteNode()

override func didMoveToView(view: SKView) {
    //Black Bird
    var blackBirdTexture = SKTexture(imageNamed:"blackbird")
    blackBirdTexture.filteringMode = SKTextureFilteringMode.Nearest

    blackBird = SKSpriteNode(texture: blackBirdTexture)
    blackBird.setScale(0.5)
    blackBird.position = CGPoint(x: self.frame.size.width * 0.35, y:
        self.frame.size.height * 0.6)

    blackBird.physicsBody =
        SKPhysicsBody(circleOfRadius:blackBird.size.height/2.0)
    blackBird.physicsBody!.dynamic = true
    blackBird.physicsBody!.allowsRotation = false

    self.addChild(blackBird)
}

override func touchesBegan(touches: Set<NSObject, withEvent event: UIEvent) {
    /* Called when a touch begins */

    for touch: AnyObject in touches {
    let location = touch.locationInNode(self)

    blackBird.color = .whiteColor()
    blackBird.colorBlendFactor = …
Run Code Online (Sandbox Code Playgroud)

xcode ios sprite-kit skspritenode swift

12
推荐指数
2
解决办法
1万
查看次数

UIAlertcontroller设置了归属消息

我们如何在UIAlertcontroller中将归属文本设置为消息.我的尝试代码如下,但它会崩溃的应用程序.

// create Attributed text

let myAttribute = [NSForegroundColorAttributeName: UIColor(red:122.0/255, green:125.0/255, blue:131.0/255, alpha:1.0),NSFontAttributeName: Constant.flinntRegularFont(15)]
let myAttribute2 = [NSForegroundColorAttributeName: UIColor.blackColor(),NSFontAttributeName: Constant.flinntMediumFont(15)]

let myString = NSMutableAttributedString(string: "You have been unsubscribed from ", attributes: myAttribute)
let myString2 = NSMutableAttributedString(string: self.course.course_name, attributes: myAttribute2)
let myString3 = NSMutableAttributedString(string: "\n\nYour refund will be initiated within one week.", attributes: myAttribute)
let myString4 = NSMutableAttributedString(string: "\n\nFor any help call us on", attributes: myAttribute)
let myString5 = NSMutableAttributedString(string: " 079-4014 9800", attributes: myAttribute2)
let myString6 = NSMutableAttributedString(string: " between …
Run Code Online (Sandbox Code Playgroud)

iphone ios swift swift2.3

12
推荐指数
1
解决办法
8775
查看次数

MKMapView重置回世界视图

如何重新设置MKMapView回到世界视图缩放级别?

iphone cocoa cocoa-touch mkmapview ios

11
推荐指数
2
解决办法
6099
查看次数

你如何在objective-c中生成一个随机日期?

我想在两个日期之间生成一个随机日期 - 例如从今天到现在60天之间的随机日期.我怎么做?

UPDATE

使用答案中的信息,我想出了这个方法,我经常使用它:

// Generate a random date sometime between now and n days before day.
// Also, generate a random time to go with the day while we are at it.
- (NSDate *) generateRandomDateWithinDaysBeforeToday:(NSInteger)days
{
    int r1 = arc4random_uniform(days);
    int r2 = arc4random_uniform(23);
    int r3 = arc4random_uniform(59);

    NSDate *today = [NSDate new];
    NSCalendar *gregorian = 
             [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    NSDateComponents *offsetComponents = [NSDateComponents new];
    [offsetComponents setDay:(r1*-1)];
    [offsetComponents setHour:r2];
    [offsetComponents setMinute:r3];

    NSDate *rndDate1 = [gregorian dateByAddingComponents:offsetComponents 
                                                  toDate:today options:0]; …
Run Code Online (Sandbox Code Playgroud)

cocoa cocoa-touch objective-c ios

11
推荐指数
4
解决办法
6966
查看次数

ios如何让UITextView检测到一个水龙头?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"touchesBegan");

    //test
    UITouch *touch = [event allTouches] anyObject];
    if ([touch tapCount] == 2) {
        NSLog (@"tapcount 2");
        [self.textview becomeFirstResponder];

    }   

     else if ([touch tapCount] == 1) {
         NSLog (@"tapcount 1");
         [self.textview becomeFirstResponder];
         [self.view performSelector:@selector(select:)];


     }

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    NSLog(@"touchesMoved");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"****touchesEnded");
    [self.nextResponder touchesEnded: touches withEvent:event]; 
    NSLog(@"****touchesEnded");
    [super touchesEnded:touches withEvent:event];
    NSLog(@"****touchesEnded");
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesCancelled:touches withEvent:event]; 
    NSLog(@"touchesCancelled");
}
Run Code Online (Sandbox Code Playgroud)

我的问题:

我想在a上点击一次时模拟两次点击UITextView …

tap uitextview uitouch ios

10
推荐指数
1
解决办法
1万
查看次数

Opencv自定义编译

我正在尝试减少ios的opencv2.framework大小.我的项目只使用core,imgproc和highgui模块.如何只使用那些模块进行编译?还是有减少尺寸的替代方案?

谢谢.

opencv ios

9
推荐指数
2
解决办法
1904
查看次数

Sprite-kit:以圆形路径移动元素

我正试图让元素在cercle的边缘移动.

  • 我在屏幕中间创建并定位了一个cercle:
var base = SKShapeNode(circleOfRadius: 200 ) // Size of Circle
base.position = CGPointMake(frame.midX, frame.midY)  
base.strokeColor = SKColor.blackColor()
base.glowWidth = 1.0
base.fillColor = UIColor(hue:1, saturation:0.76, brightness:0.94, alpha:1)
base.zPosition = 0
self.addChild(base)
Run Code Online (Sandbox Code Playgroud)
  • 然后我创建了另一个精灵并在其上添加了一个动作:
main = SKSpriteNode(imageNamed:"Spaceship")
main.xScale = 0.15
main.yScale = 0.15
main.zPosition = 1
let circle = UIBezierPath(roundedRect: CGRectMake((self.frame.width/2) - 200, CGRectGetMidY(self.frame) - 200,400, 400), cornerRadius: 200)
let circularMove = SKAction.followPath(circle.CGPath, duration: 5.0)
main.runAction(SKAction.repeatAction(circularMove,count: 2))
self.addChild(main)
Run Code Online (Sandbox Code Playgroud)

宇宙飞船的第一次旋转(见下图)完全遵循圆的边缘,但第二次迭代改变了宇宙飞船的位置并将其移出屏幕边界.这是正常的还是我做错了什么?

谢谢.

在此输入图像描述

sprite-kit swift

9
推荐指数
1
解决办法
2676
查看次数

从 SwiftUI 中的后退按钮中删除文本

简而言之,我想这样,但要使用 SwiftUI。

在此处输入图片说明

应该被移除)

到目前为止,我还没有找到NavigationBarButton直接访问 的方法,并且设法找到了以下似乎是我迄今为止可以找到的修改按钮的唯一方法:

struct MyList: View {
    var body: some View {
            Text("MyList")
            .navigationBarTitle(Text(verbatim: "MyList"), displayMode: .inline)
            .navigationBarItems(leading: Text("<"))
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我丢失了默认的返回图像并得到了一个丑陋的 <。

在此处输入图片说明

ios13 swiftui ios-navigationview

9
推荐指数
1
解决办法
6562
查看次数