小编dan*_*nd1的帖子

通过 pyTelegramBotAPI 在电报机器人中获取照片

我正在尝试开发一个简单的机器人,它可以从用户那里检索照片,然后对媒体文件进行多项操作。我正在使用 Telebot ( https://github.com/eternnoir/pyTelegramBotAPI ) 进行设计。

就我从 wiki 上看到的而言,我可以通过content_type使用特殊处理程序来划分收入消息。

但是,当我写了这么简单的方法时:

#main.py
@bot.message_handler(content_types= ["photo"])
def verifyUser(message):
    print ("Got photo")
    percent = userFace.verify(message.photo, config.photoToCompare)
    bot.send_message(message.chat.id, "Percentage: " + str(percent))

def getData(json_string):
    updates = telebot.types.Update.de_json(json_string)
    bot.process_new_updates([updates])


#server.py
app = Flask(__name__)

@app.route("/", methods=["POST", "GET"])
def hello():
    json_string = request.get_data()
    getData(json_string)
    print("....")
    print(request.data)
    return 'test is runing'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)

我遇到了这样的错误,我无法归类是我做错了什么还是 API 有问题

obj = cls.check_json(json_type)
File "/usr/local/lib/python2.7/dist-packages/telebot/types.py", line 77, in check_json
return json.loads(json_type)
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
return …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 telegram-bot py-telegram-bot-api

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

导航栏为白色,而isTranslucent = false

我有一个主导航控制器,在其中设置背景颜色

 override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationBar.backgroundColor = UIColor.blue
    self.navigationBar.isTranslucent = false
}
Run Code Online (Sandbox Code Playgroud)

但是,在那种情况下,我的导航栏会变成完全白色。当我将isTranslucent设置为true时,我的导航栏将变为透明,但这实际上不是我所需要的。我只想有蓝色的导航栏。

以防万一在我的导航控制器中

override var preferredStatusBarStyle: UIStatusBarStyle{ return .lightContent }
Run Code Online (Sandbox Code Playgroud)

并在AppDelegate中设置色调颜色

UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
Run Code Online (Sandbox Code Playgroud)

评论tintColor也没有帮助我。

这是我的“蓝色”导航栏

objective-c uinavigationcontroller ios swift

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

如何在按钮点击时观察 PublishSubject

我正在处理这种情况,我想在这里应用 RxSwift。

我有.xib带按钮的 UIView。

class RightButtonItemView: UIView {

    @IBOutlet weak var rightButtonimageView: UIImageView!
    @IBOutlet weak var rightButtonButton: UIButton!

    let performEventSegue = PublishSubject<Bool>()

    class func instanceFromNib() -> RightButtonItemView {
        return UINib(nibName: "NotificationView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as!  RightButtonItemView
    }

    override func awakeFromNib() {
       //I'm not sure how should I link button tap and my subject 
       rightButtonButton.rx.tap
    }
}
Run Code Online (Sandbox Code Playgroud)

我在 viewController 中创建了这个视图的一个实例

var rightButtonItemView = RightButtonItemView.instanceFromNib()
Run Code Online (Sandbox Code Playgroud)

Bu从我的segue点击这个按钮我需要移动到下一个VC,所以我订阅了UIView的主题

rightButtonItemView.performEventSegue.asObserver().subscribe(onNext: { (isAuthorized) in

        if isAuthorized {
            let storyboard = UIStoryboard(name: "Notifications", …
Run Code Online (Sandbox Code Playgroud)

uiview ios rx-swift rx-cocoa

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

如何从多个BezierPath创建多个路径

我正在使用swift 2.2并且我正在处理这样的问题:我有一个UIBezier对象的数组,我需要为它们创建一个笔划作为一个路径.

我以前有一个特殊的功能,但这种方法的优点,它创建了几个层.这符合我的要求,因为我需要一层

 func createStroke(line: UIBezierPath) {

        self.currentPath = CAShapeLayer()
        currentPath.path = line.CGPath
        currentPath.strokeColor = UIColor.blackColor().CGColor
        currentPath.fillColor = UIColor.clearColor().CGColor
        currentPath.lineWidth = 1
        self.view.layer.addSublayer(currentPath)

    }
Run Code Online (Sandbox Code Playgroud)

从贝塞尔线阵列创建多路径的最佳方法是什么?第一个想法是创建一个for循环循环,但我认为它不是一个干净的方式.

arrays bezier cashapelayer uibezierpath swift

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

有没有一种方法可以通过代码创建大于或等于关系的约束

我正在处理可扩展表格单元格,我的算法如下:

  1. 我创建两个视图。
  2. 创建第二个视图的高度约束,将其作为IBOutlet拖动到我的单元格中。
  3. 选择单元格后,更改所选单元格的状态。

class ExpandableCell: UITableViewCell {

    @IBOutlet weak var expandableCellHeightConstraint: NSLayoutConstraint!

    @IBOutlet weak var expandableView: UIView!

    var isExpanded:Bool = false
    {
        didSet
        {
            if !isExpanded {
                self.expandableCellHeightConstraint.constant = 0.0

            } else {
                self.expandableCellHeightConstraint.constant = 120
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

一切都很好,但我想重新调整与内部内容相关的第二个视图的大小。

这是我的约束:

在此处输入图片说明

所以,我的问题是:

将非严格值写入的最佳方法是什么self.expandableCellHeightConstraint.constant?实际上,我曾想过编写类似的东西self.expandableCellHeightConstraint.constant >= 120,但据我所知这是不可能的。

ios autolayout nslayoutconstraint swift

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