小编Pan*_*xim的帖子

使用autolayout禁用UIScrollView中的水平滚动

我想创建只有垂直滚动的视图.事实证明,在iOs中很难做到.我已经完成了这个步骤:

1)在故事板中创建UIViewController;

2)在UIViewController中的View中添加ScrollView,并为每一侧添加0个约束.

3)在scrollview中添加元素,结果如下: 在此输入图像描述

启动我的应用程序后,所有工作,但:

1)我应该如何禁用水平滚动?我向右侧添加0约束我的scrollView + 0约束到我的uilabel右侧(因为你在屏幕上看到它没有附加到右边,它有不同的约束,但在属性我设置约束= 0)并且,正如我所想,标签文本应该在我的屏幕边界,但是当我启动应用程序时我可以向右滚动,即可用文本没有换行,我的scrollview只是调整大小以适应文本.我试图设置我的scrollView在代码:scrollView.contentSize = CGSize(UIScreen.mainScreen().bounds.width, height: 800),但没有帮助.

2)如果我滚动到很多,那么出现空白区域,这不是很酷,如何解决?

iphone uiscrollview ios autolayout swift

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

Android Google Analytics xml文件

我正在阅读一个针对Android分析的新谷歌教程,这很奇怪,首先当我在我的gradle中添加这些字符串时:

classpath 'com.google.gms:google-services:1.3.0-beta1'
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

我无法同步我的项目(插件未找到错误).我不知道它是否重要.我只能添加compile 'com.google.android.gms:play-services-analytics:7.3.0'.第二,在教程中有一个步骤,我应该子类应用程序:

package com.google.samples.quickstart.analytics;

import android.app.Application;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;

/**
 * This is a subclass of {@link Application} used to provide shared objects for this app, such as
 * the {@link Tracker}.
 */
public class AnalyticsApplication extends Application {
  private Tracker mTracker;

  /**
   * Gets the default {@link Tracker} for this {@link Application}.
   * @return tracker
   */
  synchronized public Tracker getDefaultTracker() {
    if (mTracker == …
Run Code Online (Sandbox Code Playgroud)

android google-analytics

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

UIImageView方面填充 - UIImageView边界外的图像

我有一个UITableView与包含图像的单元格.我想从服务器下载一个大图像并将其插入我的单元格.

我的UITableViewCell具有固定的高度并填充整个屏幕宽度.最好的解决方案是按比例调整图像大小以适应屏幕宽度,然后裁剪固定高度的区域,但我发现调整UIImage的大小真的很难,我不明白为什么.如果你可以帮助我,这将是非常好的.

无论如何,目前,我正试图在UITableViewCell中使用AspectFill模式(我已经尝试过AspectFit和ScaleToFill并且它不是我想要的),但由于某些原因,我的图像高于单元格高度:

在此输入图像描述

我不明白我做错了什么.它不是自动布局,它是固定高度.它为什么不起作用?

uitableview uiimageview ios swift

7
推荐指数
2
解决办法
3171
查看次数

Android中的<compatible-screens>

美好的一天,我试图在谷歌播放中将屏幕尺寸限制为仅手机(即不是平板电脑).找到这篇文章后,我将其添加到我的清单文件中:

<compatible-screens>
    <!-- all small size screens -->
    <screen android:screenSize="small" android:screenDensity="ldpi" />
    <screen android:screenSize="small" android:screenDensity="mdpi" />
    <screen android:screenSize="small" android:screenDensity="hdpi" />
    <screen android:screenSize="small" android:screenDensity="xhdpi" />
    <!-- all normal size screens -->
    <screen android:screenSize="normal" android:screenDensity="ldpi" />
    <screen android:screenSize="normal" android:screenDensity="mdpi" />
    <screen android:screenSize="normal" android:screenDensity="hdpi" />
    <screen android:screenSize="normal" android:screenDensity="xhdpi" />
</compatible-screens>
Run Code Online (Sandbox Code Playgroud)

但现在看来,使用5.5 ++英寸手机的用户无法安装我的应用程序.接下来我也发现了这篇文章和图片:

在此输入图像描述

我的第一个问题 - 是否可以将屏幕尺寸限制为特定的英寸值,或者我只能使用小型,普通型,大型和Xlarge等标签?

在某些时候,我决定通过更新清单将支持英寸大小增加到7:

<compatible-screens>
    <!-- all small size screens -->
    <screen android:screenSize="small" android:screenDensity="ldpi" />
    <screen android:screenSize="small" android:screenDensity="mdpi" />
    <screen android:screenSize="small" android:screenDensity="hdpi" />
    <screen android:screenSize="small" android:screenDensity="xhdpi" /> …
Run Code Online (Sandbox Code Playgroud)

android screen-size google-play

6
推荐指数
2
解决办法
2287
查看次数

ASP.NET保存复杂的实体模型

美好的一天,我是ASP.NET的新手,我无法弄清楚为什么我的代码不起作用.我有模特:

using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Globalization;

namespace WebApp.Models
{
public class News
{
    public int NewsId { get; set; }
    public string title { get; set; }
    public string description { get; set; }
    public virtual Picture picture { get; set; }
    public int guid { get; set; }
}

public class Picture
{
    public int PictureId { get; set; }
    public byte[] image { get; set; }
    public int width { get; set; }
    public int height { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net entity-framework

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

工作拉动以禁用弹跳刷新

我有 UItableview 和活动 UIRefreshControl 用于拉动刷新操作。因此,我尝试通过取消选择 Storyboard 中 tableview 的“bounce”属性来禁用弹跳(当我滚动 UITableView 时出现)。但是,当我执行此拉动刷新操作时,它也会停止工作。对此我能做什么?我应该仅手动禁用 UIRefreshControl 的底部弹跳和左顶部弹跳吗?

\n\n

我的 viewDidLoad 方法:

\n\n
override func viewDidLoad() {\n    super.viewDidLoad()\n\n    self.refreshControl = UIRefreshControl()\n    self.refreshControl!.attributedTitle = NSAttributedString(string: "\xd0\x9e\xd0\xb1\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5")\n    self.refreshControl!.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)\n    self.edgesForExtendedLayout = UIRectEdge.None;\n    tableView.allowsMultipleSelectionDuringEditing = false;\n    tableView.tableFooterView = UIView()\n    // menu button\n    if self.revealViewController() != nil {\n        menuButton.target = self.revealViewController()\n        menuButton.action = "revealToggle:"\n        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

uitableview ios pull-to-refresh swift swift2

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

使用UIRefreshControl禁用UITableView中的底部反弹

我想禁用UITableView底部反弹,我不能在情节提要中使用标准的“ bounce”属性,bcs UIRefreshControl需要顶部反弹才能工作。所以我尝试了这个解决方案

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
    [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height)];
}
Run Code Online (Sandbox Code Playgroud)

}

如果内容高度大于屏幕大小,则效果很好,但在其他情况下崩溃: 在此处输入图片说明

如上图所示,UIRefreshControl没有被隐藏(如果UIRefreshControll被隐藏,则uitableview中只有3个单元格,底部有空白)。我试图通过将UIRefreshControl高度添加到我的方法中来解决此问题,但是它也没有帮助:

override func scrollViewDidScroll(scrollView: UIScrollView) {
    if scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height - self.refreshControl!.frame.size.height {
        scrollView.setContentOffset(CGPoint(x: scrollView.contentOffset.x, y: scrollView.contentSize.height - scrollView.frame.size.height + self.refreshControl!.frame.size.height), animated: false)
    }
}
Run Code Online (Sandbox Code Playgroud)

我顶部有空白,RefreshControl停止工作:

在此处输入图片说明

我究竟做错了什么?谢谢。

PS我的viewDidLoad方法:

override func viewDidLoad() {
    super.viewDidLoad()

    self.refreshControl = UIRefreshControl()
    self.refreshControl!.attributedTitle = NSAttributedString(string: "??????????")
    self.refreshControl!.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
    self.edgesForExtendedLayout = UIRectEdge.None;
    tableView.allowsMultipleSelectionDuringEditing = false;
    tableView.tableFooterView = UIView() …
Run Code Online (Sandbox Code Playgroud)

uitableview ios uirefreshcontrol swift

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

Android TV ImageCardView 标题换行

我正在开发适用于 Android TV 的应用程序并使用 Leanback 库。

以谷歌为例,他们用来public class CardPresenter extends Presenter显示内容。问题是,我想显示标题中的所有文本,即不要剪切它。

在此输入图像描述

我已经尝试过:

1) 通过以编程方式设置 LayoutParams 来解决此问题:cardView.findViewById(R.id.title_text).setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));

2)我查看了 lb_image_card_view.xml 文件中的ImageCard。有趣的是,ID为“title_text”的TextView已经有android:layout_height="wrap_content"参数,但看起来不起作用?这是一个错误吗?

3)对于备份计划,我可以为 ImageCardView 创建自己的类,但这个解决方案似乎很难。

谢谢。

更新。

我使用了下面的答案,但我必须修改代码以获得更好的性能:

cardView.setOnFocusChangeListener((view, isFocused) -> {
        if (isFocused) {
            ((TextView) cardView.findViewById(R.id.title_text)).setMaxLines(5);
        }
        else {
            ((TextView) cardView.findViewById(R.id.title_text)).setMaxLines(1);
        }
    });
Run Code Online (Sandbox Code Playgroud)

java android android-tv

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

滚动uitableview时重复单元格

我正在开发新闻源,我正在使用uitableview来显示数据.我在其他线程中同步加载每个单元格数据并使用协议方法显示加载的数据:

func nodeLoaded(node: NSMutableDictionary) {
    for var i = 0; i < nodesArray.count; ++i {
        if ((nodesArray[i]["id"] as! Int) == (node["id"] as! Int)) {
            nodesArray[i] = node
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是,当我滚动我的uitableview(同时加载数据时),我的一些单元重复(8行具有相同的内容,如第一行,或6行具有相同的内容,如第二行).当我滚动一段时间后(我想在加载数据后)然后一切都变得正常了.我寻找答案,发现我必须在cellForRowAtIndexPath检查单元格是否为nill,但是在swift中我的代码与目标C中的代码不同:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell: NewsCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! NewsCell
    var node = nodesArray[indexPath.row] as! NSDictionary
    if (node["needLoad"] as! Bool) {
        dbHelper.getNode(node["id"] as! Int, hash: node["id"] as! Int, tableName: DbHelper.newsTableName, callback: self)
    } else {
        cell.id = node["id"] as! Int …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios swift

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

UITableView平滑滚动

我在每个单元格中都有UITableView图像,我希望滚动顺畅.所以我在stackerflow上阅读了一些帖子,现在我在后台线程中加载我的图片:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell: BuildingStatusCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! BuildingStatusCell
    cell.selectionStyle = UITableViewCellSelectionStyle.None
    var node = nodesArray[indexPath.row] as! NSMutableDictionary
    if !checkIfImagesLoaded(node[Api.pictures] as! NSMutableArray) {
        cell.id = node[Api.buildingStatusId] as! Int
        cell.date.text =  node[Api.date] as? String
        cell.count.text = String((node[Api.pictures] as! NSMutableArray).count)
        cell.indicator.hidesWhenStopped = true
        cell.indicator.startAnimating()
        dbHelper.getBuildingStatusNode(node, callback: self)
    } else {
        cell.id = node[Api.buildingStatusId] as! Int
        cell.date.text =  node[Api.date] as? String
        cell.count.text = String((node[Api.pictures] as! NSMutableArray).count)
        dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.value), 0)) {
            var image = …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

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