我正在使用好友 sdk
此示例告诉我如何添加个人资料图片,我尝试了各种方法,但是当我尝试使用此代码时
client.CreateUserAsync("username","password").ContinueWith(r => { var user = r.Result;
// upload a profile photo
Stream photoStream = GetSomePhoto();
user.AddProfilePhotoAsync(photoStream);
});
Run Code Online (Sandbox Code Playgroud)
这是我的代码,但它给了我数组问题
var img = loginImagePicker.Image.AsPNG().AsStream();
var hu = await user.AddProfilePhotoAsync(img);
Run Code Online (Sandbox Code Playgroud)
这就是问题

有什么建议吗?
我正在使用 ios 7,我需要做:
在单独的线程中,我想从网络创建图像并将其放入 UIImageView。我需要每 200 毫秒执行一次。
我的代码看起来像:
- (void)startPreview:(CGFloat)specialFramesRates;
{
if(isPreview)
return;
[Utils runOnThread:^{
[Log log:@"Start preview"]; //here we have a leak
isPreview = YES;
while(isPreview) {
[self getNewBitmap];
sleep(fpsTime);
if(!isPreview)
break;
if(checkAvabilityCam > 10)
break;
}
[Log log:@"Stoped preview"];
}];
}
- (void)getNewBitmap
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setTimeoutInterval:1];
[request setHTTPMethod:@"GET"];
NSError *requestError;
NSURLResponse *urlResponse = nil;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if(delegate && response) {
checkAvabilityCam = 0; …Run Code Online (Sandbox Code Playgroud) 我的应用程序从后端加载图像并将它们显示在 UITableViewCell 中,其中包含一个 UIImageView 来显示它以及一些标签和按钮。
我已使用“重置为建议的约束”选项将建议的约束添加到 UITableViewCell。
这是检索数据后的一些代码:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = PostTableViewCell()
if (self.posts.count == 0) { return cell }
let post = posts[indexPath.row]
// Instancia o reuse identifier
if post["post_image"] != nil {
cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.PostWithImage, for: indexPath) as! PostTableViewCell
} else {
cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.PostWithoutImage, for: indexPath) as! PostTableViewCell
}
return cell
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
var …Run Code Online (Sandbox Code Playgroud) 我试图将 2 个 uiimages 保存在一起,然后将组合的图像放入一个名为 finalImage 的图像视图中。但是,我收到错误消息,指出我已为我的问题分配了标题。只是想将组合的 uiimage 放在图像视图中。
@IBOutlet var finalImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let bottomImage:UIImage = UIImage(named: "pic")!
let topImage:UIImage = UIImage(named:"wall")!
// Change here the new image size if you want
let newSize = CGSize(width: bottomImage.size.width, height: bottomImage.size.height)
UIGraphicsBeginImageContextWithOptions(newSize, false, bottomImage.scale)
bottomImage.draw(in: CGRect(x: 0,y: 0,width: newSize.width,height: newSize.height))
topImage.draw(in: CGRect(x: 0,y: 0,width: newSize.width,height: newSize.height), blendMode:CGBlendMode.normal, alpha:1.0)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
//error line
finalImage.image = newImage.images
}
Run Code Online (Sandbox Code Playgroud) 我试图在整个应用程序的导航栏右侧放置一个图标。这是除主屏幕之外的所有地方(尽管那里也可以,因为我将它隐藏在该视图控制器上):顶部的表视图控制器,以及图像最右侧的地图视图和表视图控制器以下。
这段代码神秘地用于在一个视图控制器(收藏夹视图控制器,左上角)上设置导航栏中心的图标,这是一个 tableview 控制器,与嵌入在导航控制器中的 UIViewController 隔离:
let yelpIcon = UIBarButtonItem(image: UIImage(named: "Yelp_trademark_RGB_outline"), style: .plain, target: self, action: nil)
self.navigationController!.navigationItem.rightBarButtonItem = yelpIcon
Run Code Online (Sandbox Code Playgroud)
我的 Map 和 TableViewControllers(最右边)嵌入在导航控制器中,每个都嵌入在标签栏控制器中。我无法通过在 Interface Builder 中创建导航项并设置其图像或以编程方式显示图像。
在 SO 上强烈推荐此代码,但在我尝试时没有结果(我将操作设置为 nil,因为我不需要它执行任何操作):
let button1 = UIBarButtonItem(image: UIImage(named: "myimage"), style: .plain, target: self, action: Selector("action"))
self.navigationItem.rightBarButtonItem = button1
Run Code Online (Sandbox Code Playgroud)
注意:导航栏采用黑色 barTintColor 风格化,这应该没什么区别,但我想我会分享。图像是我的资产文件夹中的 PNG。在使用调试视图层次结构时,我遇到了这两层似乎阻止了我的图像出现(尽管它们不使用后退按钮执行此操作)。
实例地址 0x7fa8b7b10aa0 是一个 UIVisualEffectSubView。我不确定这是否是问题,但我也不知道如何关闭它。我已将嵌入导航控制器的导航栏中的视图色调颜色更改为透明,并关闭不透明度。都没有工作。
如何让导航栏右侧的图像出现?
我正在使用 swift 制作一个应用程序,该应用程序调用 Google Places api 以生成位置的 JSON 文件,包括生成的位置图像。这些图像作为 URL 给出,我需要将它们转换为 UIImage,然后将这些图像附加到数组中。打开 URL 的内容时,我可以看到图像,但这些图像没有附加到数组中。这是我的视图控制器的类,它试图生成所述图像:
import Foundation
import UIKit
import WebKit
class ImageViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
var photos: [Photo]?
var uiImages: [UIImage]?
override func viewDidLoad() {
for photo in photos! {
let url = URL(string:"https://maps.googleapis.com/maps/api/place/photo?photoreference=\(photo.reference)&sensor=false&maxheight=\(photo.height)&maxwidth=\(photo.width)&key=AIzaSyC_SoYT7VnYnyz3GAb7qqbXjZeLFG5GE70")
let data = try? Data(contentsOf: url!)
let image: UIImage = UIImage(data: data!)!
self.uiImages?.append(image)
print(image)
print(self.uiImages)
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这个循环中,我告诉代码在追加发生后打印“image”和数组“uiImages”。但是,我在打印图像数组时返回 nil,但对于图像本身不返回 nil。

我觉得这可能与方法的异步有关,但我也尝试在主线程上附加,但这并没有改变任何东西。此外,“photos”变量不是 nil,它是在视图控制器实例化时设置的。
这是 Photo 类的代码:
import Foundation
struct Photo {
var …Run Code Online (Sandbox Code Playgroud) 我正在和Swift一起做骰子游戏.我想让玩家选择在他们点击时转动一个'骰子'.因此,我想使用UIButton作为骰子.我把骰子作为UIImages工作,现在我想把UIImages转移到UIButtons.但在这样做的过程中我遇到了一个错误:
参数标签'(名为:)'与任何可用的重载都不匹配.
我有点无能为力,不知道如何解决这个问题.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var dice1: UIButton!
@IBOutlet weak var dice2: UIButton!
let stenenArray = ["Steen1, Steen2, Steen3, Steen4, Steen5, Steen6"]
var randomDiceIndex1 : Int = 0
var randomDiceIndex2 : Int = 0
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func buttonPressed(_ sender: Any) {
updateDiceImages()
}
func updateDiceImages(){
dice1 = UIButton(named: stenenArray[randomDiceIndex1])
dice2 = UIButton?(named: stenenArray[randomDiceIndex2])
randomDiceIndex1 = Int(arc4random_uniform(6))
randomDiceIndex2 = Int(arc4random_uniform(6))
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 PHImageCachingManager 来获取 PHAsset 的图像。我需要使用opportunistic模式,以便首先加载可用的低分辨率图像,然后在全分辨率可用时加载它。
出于某种原因,我不断收到以下警告,但我的低分辨率图像无法加载。图像仅在获取最高分辨率时加载(从 iCloud)。
警告:
"First stage of an opportunistic image request returned a non-table format image, this is not fatal, but it is unexpected."
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
let imageRequestOptions = PHImageRequestOptions()
imageRequestOptions.isNetworkAccessAllowed = true
imageRequestOptions.deliveryMode = .opportunistic
let imageCachingManager = PHCachingImageManager()
imageCachingManager.requestImage(for: asset , targetSize: PHImageManagerMaximumSize, contentMode: .aspectFill, options: imageRequestOptions) { (image, infoDict) in
DispatchQueue.main.async {
if self.myImageView.identifierTag == asset.localIdentifier {
self.myImageView.image = image
}
}
}
Run Code Online (Sandbox Code Playgroud) 请检查此附加代码并缩短屏幕。当我设置容器视图的颜色时它工作正常,但是当我在单元格中添加 UIImage 时它不起作用。我更改了 imageview 内容模式,但它不起作用。
class ViewController: UIViewController {
@IBOutlet weak var segColumn: UISegmentedControl!
@IBOutlet weak var collectionView: UICollectionView!
fileprivate var items: [UIImage] = [ // My images ]
override func viewDidLoad() {
super.viewDidLoad()
self.setup()
}
}
extension ViewController: UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCell
cell.imgCell.image = items[indexPath.row]
cell.imgCell.contentMode = .scaleAspectFill
cell.contentView.backgroundColor = …Run Code Online (Sandbox Code Playgroud) uiimageview uiimage uicollectionview uicollectionviewlayout swift
uiimage ×10
ios ×7
swift ×6
uiimageview ×3
swift3 ×2
asynchronous ×1
blend-mode ×1
border ×1
c# ×1
memory-leaks ×1
phasset ×1
stream ×1
uibutton ×1
uitableview ×1
url ×1
xamarin.ios ×1
xcode ×1