小编Pha*_*inh的帖子

iOS 7缩放在使用AutoLayout的ScrollView中无效,但在iOS8/9中工作

我用缩放图像做了一个演示UIScrollView.我ViewController只包含一张图片.问题是图像无法放大iO7(我已经测试过iPhone4S-iOS7)但在iOS8/中完美地工作iOS9.
关于如何修复它的任何想法?

这是我的代码

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
@property (weak, nonatomic) IBOutlet UIView *contentview;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
        float minimumScale = [_contentview frame].size.width /[_scrollview frame].size.width;
        _scrollview.maximumZoomScale = 5;  //Change as per you need
        _scrollview.minimumZoomScale = minimumScale;  //Change as you need
        _scrollview.zoomScale = minimumScale;
        _scrollview.delegate =self;
        _scrollview.clipsToBounds = YES;
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return self.contentview;
}

@end
Run Code Online (Sandbox Code Playgroud)

这是布局结构 …

objective-c uiscrollview ios autolayout

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

Xcode更改Command +单击以控制+单击

我想更改默认快捷键以打开相关的源代码(现在是Command+click)Control+click(像其他IDE:Eclipse,AndroidStudio)

我试图找到Xcode->Preference->Key Bindings但无法找到更改命令Command+click

我怎样才能改变它.任何帮助或建议将非常感谢.

xcode keyboard-shortcuts ios

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

如何根据文本计算TextView高度

我使用下面的代码计算文本的高度,然后为UILabel和设置此高度UITextView

CGSize targetSize = CGSizeMake(300, CGFLOAT_MAX);
NSString *message = @"The Internet connection appears to be offline.";

NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
CGSize boundingBox = [message boundingRectWithSize:targetSize
                                              options:NSStringDrawingUsesLineFragmentOrigin
                                           attributes:@{NSFontAttributeName:FontOpenSanWithSize(14)}
                                              context:context].size;

CGSize size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height));
// it will return size:width = 299 and size height 20
// => if I use this height and set for UILabel, it can display full content
// => if I use this height and set for UITextView, it can not display …
Run Code Online (Sandbox Code Playgroud)

uitextview ios

7
推荐指数
3
解决办法
9875
查看次数

PopupWindow位于某些设备的状态栏之上

这是我的代码show a PopupWindow

View rootView = activity.getWindow().getDecorView().getRootView();
mPopupWindow.showAtLocation(rootView, Gravity.NO_GRAVITY, 0, 0);
Run Code Online (Sandbox Code Playgroud)

当我测试它时Samsung,Nexus它显示在状态栏下面的设备
但是当我在Sony设备上测试时它显示在状态栏上方(如下图所示)

那么哪个设备显示正确或我做错了什么?任何帮助或建议将非常感谢

在此输入图像描述

android sony popupwindow nexus-s

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

如何接收Facebook Deep Link数据

AndroidManifest我有

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>

        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data
            android:host="linhtestdeeplink"
            android:scheme="app"/>
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

MainActivity

AppLinkData.fetchDeferredAppLinkData(this,
        new AppLinkData.CompletionHandler() {
            @Override
            public void onDeferredAppLinkDataFetched(final AppLinkData appLinkData) {
                // Process app link data
                Log.i("TAG", "Deep link receive" + appLinkData);
            }
        }
);
Run Code Online (Sandbox Code Playgroud)

Facebook页面中,我测试了Deep Link之类的

在此输入图像描述

我的应用收到了通知,当我点击通知时它将启动我的应用程序,但 appLinkData始终null.
我也发送,linhtestdeeplink://tripId=1但它也是null.
任何帮助或建议将非常感谢.
我正在使用facebook sdk 4.5 compile 'com.facebook.android:facebook-android-sdk:[4,5)'

android facebook deeplink

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

IOS:可以在每个角落使用不同值的圆形半径

我想我的全才UIView与这样的价值
top-left-radius:20; bottom-right-radius:5; bottom-left-radius:5;top-right-radius:10;

   //For rounder `UIRectCornerBottomLeft & UIRectCornerBottomRight` I use

    UIBezierPath *maskPath0 = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5.0, 5.0)];

    CAShapeLayer *maskLayer0 = [[CAShapeLayer alloc] init];
    maskLayer0.frame = self.bounds;
    maskLayer0.path  = maskPath0.CGPath;
    self.messageView.layer.mask = maskLayer0;


    //For rounder `TopRight` I use

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];

    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path  = maskPath.CGPath;
    self.messageView.layer.mask = maskLayer;


    //For rounder `TopLeft` I use

    UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopLeft) cornerRadii:CGSizeMake(20.0, …
Run Code Online (Sandbox Code Playgroud)

layer ios uibezierpath

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

UILabel截断尾部并跳过不完整的单词

我有一条线UILabel.它有宽度=屏幕宽度,现在的内容是(内容UILabel可以改变)

你有30秒的时间在面试中留下印象

目前,我UILabel的尾部被截断,"持续时间"这个词并不完整

self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
Run Code Online (Sandbox Code Playgroud)

我想要的是我想要我UILabel 仍然截断的尾巴,显示完整的单词.
如下图所示

在此输入图像描述

任何帮助或建议将非常感谢.

uilabel ios

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

在EditText android中禁用SPACE键

我创建了EditText,如下所示.

<EditText
        android:id="@+id/et_regis_num"
        android:maxLines="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:digits="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        android:hint="@string/txt_reg_num"
        android:inputType="textCapCharacters"
        android:maxLength="10" />
Run Code Online (Sandbox Code Playgroud)

在这个edittext中,我不想按SPACE键,但是当我按下SPACE键时,它正在作为BACKSPACE键.意味着它每次按两次按下一个字符.

android keycode keyevent android-edittext

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

在目标android 26的所有窗口上方显示PopupWindow

我想在PopupWindow没有请求的情况下显示所有窗口(例如:另一个弹出窗口,对话框,另一个活动屏幕),SYSTEM_ALERT_WINDOW所以我使用WindowManager.LayoutParams.TYPE_TOAST

public void showSimplePopupWindow() {
    final View popupView = layoutInflater.inflate(R.layout.popup_layout_2, null);

    final PopupWindow popupWindow = new PopupWindow(popupView);
    ...config popup window...

    PopupWindowCompat.setWindowLayoutType(popupWindow, WindowManager.LayoutParams.TYPE_TOAST);
    popupWindow.showAsDropDown(findViewById(R.id.button_show_popup_window));
}
Run Code Online (Sandbox Code Playgroud)

如果我设置它在所有Android版本中运行良好targetSdkVersion < 26 .

目前,如果我保留上面的代码并将目标更新targetSdkVersion为26,那么它会因设备api 25-26而异常崩溃android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@859d91f is not valid; is your activity running?

我看到它TYPE_TOAST已被弃用sdk 26,他们建议使用TYPE_APPLICATION_OVERLAY.但是,当我使用时TYPE_APPLICATION_OVERLAY,AndroidStudio显示TYPE_APPLICATION_OVERLAY所需的api 26.因此,TYPE_APPLICATION_OVERLAY只有设备api 26才能正常工作,对于设备api <26,它会崩溃(即使我已启用Display/Draw over other app …

android popupwindow android-8.0-oreo

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

Android ConnectivityManager onAvailable 有时未返回

我们使用 AndroidConnectivityManager来监听我们的应用程序内的互联网连接变化,如下所示。

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        ConnectionStateMonitor().enable(this)
    }

    class ConnectionStateMonitor : NetworkCallback() {
        private val networkRequest: NetworkRequest = NetworkRequest.Builder()
            .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
            .addTransportType(NetworkCapabilities.TRANSPORT_WIFI).build()

        fun enable(context: Context) {
            val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
            connectivityManager.registerNetworkCallback(networkRequest, this)
        }

        override fun onAvailable(network: Network) {
            Log.i(TAG, "onAvailable ")
        }

        override fun onLost(network: Network?) {
            super.onLost(network)
            Log.i(TAG, "onLost ")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

除了我们遇到的两个问题外,此实现运行良好

  1. 如果我们同时使用 wifi 和移动数据连接到互联网并关闭 wifi 有时会onLost()触发回调onAvailable(),如预期的那样,但在其他情况下 onLost()触发这是不正确的。

  2. 如果我们没有互联网连接并打开应用程序onLost()不会被触发,但是如果我们有互联网连接并打开应用程序 …

android android-connectivitymanager

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